Constructor calls during inheritance : Constructor « Class « Java






Constructor calls during inheritance

Constructor calls during inheritance
 
// : c06:Cartoon.java
// Constructor calls during inheritance.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

class Art {
  Art() {
    System.out.println("Art constructor");
  }
}

class Drawing extends Art {
  Drawing() {
    System.out.println("Drawing constructor");
  }
}

public class Cartoon extends Drawing {
  public Cartoon() {
    System.out.println("Cartoon constructor");
  }

  public static void main(String[] args) {
    Cartoon x = new Cartoon();

  }
} ///:~



           
         
  








Related examples in the same category

1.Paying attention to exceptions in constructorsPaying attention to exceptions in constructors
2.Order of constructor callsOrder of constructor calls
3.Constructors and polymorphism don't produce what you might expectConstructors and polymorphism don't produce what you might expect
4.Constructor initialization with compositionConstructor initialization with composition
5.Demonstration of a simple constructorDemonstration of a simple constructor
6.Constructors can have argumentsConstructors can have arguments
7.Show Constructors conflicting
8.Show that if your class has no constructors, your superclass constructors still get calledShow that if your class has no constructors, your superclass constructors still get called
9.A constructor for copying an object of the sameA constructor for copying an object of the same
10.Create a new instance of a class by calling a constructor with arguments