下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果。class People {String name;public People() {System.out.print(1);}public People(String name) {System.out.print(2);this.name = name;}}class Child extends People {People father;public Child(String name) {System.out.print(3);this.name = name;father = new People(name + ":F");}public Child() {System.out.print(4);}}
A. 312
B. 32
C. 432
D. 132
查看答案
请写出以下程序输出结果:父类: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();}}
从例5-2的Citizen类继承,定义一个教师Teacher类,并添加属性教师代码、教师职位和主讲课程,覆盖父类的display()方法。分别调用父类和子类的方法显示教师信息。