选C
父类没有无参的构造函数,所以子类需要在自己的构造函数中显式调用父类的构造函数, 添加
super("nm"); 否则报错: Implicit super constructor
Person() is undefined. Must explicitly invoke another constructor
class Person {
String name = "No name";
public Person(String nm) {
name = nm;
}
}
class Employee extends Person {
public Employee(String nm) {
super(nm);
// TODO Auto-generated constructor stub
}
String empID = "0000";
}
public class Test {
public static void main(String args[]) {
Employee e = new Employee("123");
System.out.println(e.empID);
}
}