class Person{
String name="No name";
public Person(String nm){ name=nm;}
}
class Employee extends Person {
String empID="0000";
public Employee(String id) { empID=id;}
}
public class EmployeeTest{
public static void main(String [] args){
Employee e=new Employee("4321");
System.out.println(e.empID);
}
}
A. 4321
B. 0000
C. An exception is thrown at Runtime
D. Compilation fails
D) Compilation fails
Employee constructor implicitly calls super(), but Person has no default constructor declared.
Default constructor is only created by the compiler if there is no other constructor declared.
No comments:
Post a Comment