SE450: Constructors: super constructors [3/32] Previous pageContentsNext page

super constructors [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package subclass.ex7;

public class M {
  public static void main(String[] argv) {
    new B(1);
    new C();
  }
}
class A {
  A(int i) {System.out.println("A(int)");}
}
class B extends A {
  B(int i) {
    super(i);
    System.out.println("B(int)");
  }
}
class C extends B {
  // The following will not compile!
  //  C() {System.out.println("C");}
  C() {
    super(0);
    System.out.println("C");
  }
}

Previous pageContentsNext page