2009年2月3日 星期二

第14題 SampleCode

11. class Person{
12. String name = "No name";
13. public Person(String nm){name = nm;}
14. }
15.
16. class Employee extends Person{
17. String empID = "0000";
18. public Employee(String id){empID = id;}
19. }
20.
21. class EmployeeTest{
22. public static void main(String[] args){
23. Employee e = new Employee("4321");
24. System.out.println(e.empID);
25. }
26. }
What is the result?
A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.
---------------------------------------------------------------------
答案:D



class test14{
String name = "No name";
public test14(String nm){name = nm;}
}
class Employee extends test14{
String empID = "0000";
public Employee(String id){empID = id;}
}
//Implicit super constructor test14() is undefined.
//Must explicitly invoke another constructor

class EmployeeTest{
public static void main(String[] args){
Employee e = new Employee("4321");
System.out.println(e.empID);
}
}

ANS:
D. Compilation fails because of an error in line 18.

--------------------------------------------------------------------------------------
error msg
Implicit super constructor test14() is undefined. Must explicitly invoke another constructor

沒有留言:

張貼留言