Following code requires superclass constructor need to be implicitly defined for this keyword to work
public class SuperEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
Child c=new Child(10,"AK");
c=new Child("Hi","AK");
}
}
class Parent{
int n;
String s;
Parent(int n, String s){
this.n=n;
this.s=s;
System.out.println("Parent constructor arg value is "+n +" and " +s);
}
}
class Child extends Parent{
Child(int i, String n){
super(i,n);
System.out.println("child 2nd Constructor");
}
Child(String s, String s1){
this(s,s1,"hello");
}
/*here im getting error in eclipse IDE which says "Implicit super constructor Parent() is undefined. Must explicitly invoke another constructor*/
Child(String s, String s1, String s3){
System.out.println("values are "+s+" "+s1+" "+s3);
}
}
The above code is typed in eclipse neon ide.
Compilation error is shown in Child constructor with three arguments.
- Does this keyword requires SuperClass constructor to be implicitly defined.