重写的时候,构造器中调用方法容易错的问题
2013-03-27 19:45
253 查看
package com.huxin.test.overvide;
public class OverrideTest {
public static void main(String[] args) {
Son son = new Son();
// 结果是:father中a的方法 son中b的方法
}
}
class Father{
public Father(){
//c(); 这样会报错哦
a();
b();
}
private void a(){
System.out.println("father中a的方法");
}
public void b(){
System.out.println("father中b的方法");
}
}
class Son extends Father{
public Son(){
}
private void a(){
System.out.println("son中a的方法");
}
public void b(){
System.out.println("son中b的方法");
}
public void c(){
System.out.println("son中c的方法");
}
}
public class OverrideTest {
public static void main(String[] args) {
Son son = new Son();
// 结果是:father中a的方法 son中b的方法
}
}
class Father{
public Father(){
//c(); 这样会报错哦
a();
b();
}
private void a(){
System.out.println("father中a的方法");
}
public void b(){
System.out.println("father中b的方法");
}
}
class Son extends Father{
public Son(){
}
private void a(){
System.out.println("son中a的方法");
}
public void b(){
System.out.println("son中b的方法");
}
public void c(){
System.out.println("son中c的方法");
}
}
相关文章推荐
- java方法重写的时候,一个调用父类还是子类方法的问题
- 一个.NET工程在调用Java方法的时候不能创建JVM的问题及其原因
- UIView设置为自动适配屏幕时,当用户旋转设备的时候,会调用layoutSubviews方法,我们只需重写 这个方法,然后判断用户屏幕的方向。在调整每个空间的位置即可。
- 百度 地图 slidingmenu 黑边 使用截图的方式解决黑边问题,步骤: 1.slidingMenu打开的时候调用BaiduMap的snapshot方法截图获取Bitmap对象; 2.使用
- Java的重写与调用父类方法问题
- JAVA笔试题总结3:父类构造器调用被子类重写方法
- 关于重写CListCtrl时候 MeasureItem不被调用的问题
- 在Viewpager的子Activity中startActivityForResult调用其他Activity时候遭遇到onActivityResult方法不响应的问题.
- Java的重写与调用父类方法问题
- 在TabHost的子Activity中startActivityForResult调用其他Activity时候遭遇到onActivityResult方法不响应的问题.
- Winform 调用WCF客户端,所有服务端方法在运行的时候均找不到(编译没有问题)
- Java 子类未重写的方法调用父类还是子类的问题
- 理解和掌握类的加载过程以及子类继承父类后,重写方法的调用问题
- Winform 调用WCF客户端,所有服务端方法在运行的时候均找不到(编译没有问题)
- 子类、父类相互调用构造器和成员方法问题
- 关于子类创 4000 建对象调用父类方法时this的问题(以及方法重写)
- 在Viewpager的子Activity中startActivityForResult调用其他Activity时候遭遇到onActivityResult方法不响应的问题
- 关于重写的listview adapter中,在getView()方法中,打印语句时,相同的position打印了多次,重复调用问题
- 关于重写servlet的service()方法时调用父类service方法的问题
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。