public class A extends Base {
double height = 6.0;
public static void main(String args[]) {
System.out.println("hello");
A a = new A();
}
public A() {
super(); // [The compiler does this if you delete this line.]
System.out.println("in A() constructor");
showAttributes();
System.out.println("end of A() constructor");
}
protected void showAttributes() {
System.out.println("A.showAttributes() : " + getClass().getSimpleName() + "(height=" + height + ")");
super.showAttributes(); // [Added this line]
}
}
class Base {
double weight = 150.0;
protected Base() {
System.out.println("in B() constructor");
showAttributes();
System.out.println("end of B() constructor");
}
protected void showAttributes() {
System.out.println("B.showAttributes() : " + getClass().getSimpleName() + "(weight=" + weight + ")");
}
}
Comments
0 B
|👍
/👎