public class TestExtend extends Base {
public static void main(String[] args) {
Base b = new TestExtend();
b.amethod();
}
@Override
public void amethod() {
System.out.println("Driv..");
}
}
class Base {
Base() {
amethod();
}
public void amethod() {
System.out.println("Base ");
}
}
public static void main(String[] args) {
Base b = new TestExtend();
b.amethod();
}
@Override
public void amethod() {
System.out.println("Driv..");
}
}
class Base {
Base() {
amethod();
}
public void amethod() {
System.out.println("Base ");
}
}
解决方案 »
- 如何在 hibernate.cxf.xml文件中引入外部文件
- 网站数据全站静态化。数据库是压力轻了。但是产生了大量.html
- 页面的共通提取出来的问题(struts框架)
- 用axis来调用Web logic开发的webService,急!!!
- tomcat的问题
- iReprot中要用表格的形式显示出来那些像excel中的线应该怎么运用的,怎么来实现的
- 哪里有Tomcat的安装版下载?
- apache 和tomcat的问题!
- 为啥出这个错啊:java.security.AccessControlException: access denied
- dbutils的updata方法无效,后台也不报错?
- 在J2EE5中可以使用J2EE6的包吗
- java拆分日期
Driv..
据我理解,因为TestExtend继承了父类Base,覆写了amethod()方法
,所以子类的构造函数super()方法也覆写了父类构造函数里的amethod()方法
对象b是TestExtend类对象,在new的时候调用构造函数输出第一个Driv..
第二Driv..是TestExtend类实例的amethod方法
b.amethod();直接调用子类覆写过的amethod();方法。多态的特性而已
Base b = new TestExtend();
//调用Base的构造方法,构造方法里面调用method()方法,但method()方法被子类重写,打印driv..
b.amethod();
//再次调用重写后的method(),打印driv...
}