Posted in 面试题 onNovember 18, 2015
答:父类:
package test;
public class FatherClass {
public FatherClass() {
System.out.println(“FatherClass Create”);
}
}
子类:
package test;
import test.FatherClass;
public class ChildClass extends FatherClass {
public ChildClass() {
System.out.println(“ChildClass Create”);
}
public static void main(String[] args) {
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
输出结果:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
package test;
public class FatherClass {
public FatherClass() {
System.out.println(“FatherClass Create”);
}
}
子类:
package test;
import test.FatherClass;
public class ChildClass extends FatherClass {
public ChildClass() {
System.out.println(“ChildClass Create”);
}
public static void main(String[] args) {
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
输出结果:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@