class constructorone
{
constructorone(int a)
{
System.out.println("constructor of super class");
}
}
class constructortwo extends constructorone
{
constructortwo(int b)
{
System.out.println("constructor of sub class");
}
}
class constructoroutput5 {
public static void main(String[] args) {
constructortwo b1= new constructortwo(10);
}
}
A)
Output :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Implicit super constructor constructorone() is undefined. Must explicitly invoke another constructor
at constructortwo.<init>(constructoroutput5.java:10)
at constructoroutput5.main(constructoroutput5.java:19)
above program causes compilation error as there is no zero argument constructor in super class.
Because the compiler written only super() method. That calls only zero argument constructor. Because it doesn’t contain parameters.
But we can specify explicitly in the super() method as super(10) then compilation error cannot be raised.
Comments
Post a Comment