Just simply fill in the missing code ...
package com.twisters;
class Base {
public int a;
public int getA(){
return a;
}
}
public class Child extends Base{
private int a;
Child(int value){
/* Code goes here */
}
public static void main(String[] args) {
Base b = new Child(10);
System.out.println(b.getA()); //This should print 10
}
}
Got an answer? Why don’t you leave it here.
package com.twisters;
ReplyDeletepublic class Child extends Base{
private int a;
Child(int value){
super.a = value;
}
public static void main(String[] args) {
Base b = new Child(10);
System.out.println(b.getA()); //This should print 10
}
}
super.a = value;
ReplyDeletethe code raises a compilation error
ReplyDeletebecause without a Base class constructor you can not define Child class Constructor
nsureshreddy@live.com