ProAnswers.org

How to use Inheritance, constructors and arguments?

class A {
A(int i) {
System.out.println(“A constructor”);
}
}

class B extends A {
B(int i) {
super(i);
System.out.println(“B constructor”);
}
}

class C extends B {
C() {
super(11);
System.out.println(“C constructor”);
}
}

public class MainClass {
public static void main(String[] args) {
C x = new C();
}
}
output
A constructor
B constructor
C constructor