class constructorone
{
constructorone(int a)
{
System.out.println("constructor of super class");
}
}
class constructorone2 extends constructorone
{
constructorone2()
{
//super();->this method is written by compiler in compile time. For non parameterized constructor
System.out.println("constructor of sub class");
}
}
class constructoroutput4 {
public static void main(String[] args) {
constructorone2 b = new constructorone2();
}
}
A)
Output :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Implicit super constructor constructorone() is undefined. Must explicitly invoke another constructor
at constructorone2.<init>(constructoroutput4.java:10)
at constructoroutput4.main(constructoroutput4.java:17)
Reason:
The above program causes compilation error as there is no zero argument constructor in super class.
Explanation:
Super class object is created in compile time. super() method is written in super class constructor method as first statement. That’s why the super class doesn’t contain zero argument constructor so that’s why error is raised.
Comments
Post a Comment