ConstuctorDemo.java
Download ConstuctorDemo.java
1: // Demo of order of constructor calls with inheritance.
2: //
3: // Written 11/2010 by Wayne Pollock, Tampa Florida USA
4:
5: class Parent {
6: public Parent () {
7: System.out.println( "Parent no-arg constructor invoked.");
8: }
9: }
10:
11: class Child extends Parent {
12: public Child () {
13: this(1);
14: System.out.println( "Child no-arg constructor invoked." );
15: }
16:
17: public Child (int num) {
18: System.out.println( "Child int constructor invoked." );
19: }
20: }
21:
22: public class ConstuctorDemo {
23: public static void main ( String [] args ) {
24: Child c = new Child();
25: }
26: }