Inheritance, constructors and arguments : Inheritance Composition « Class « Java

Inheritance, constructors and arguments

Inheritance, constructors and arguments

// :
// Inheritance, constructors and arguments.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// See copyright notice in CopyRight.txt.

class Game {
  Game(int i) {
    System.out.println("Game constructor");

class BoardGame extends Game {
  BoardGame(int i) {
    System.out.println("BoardGame constructor");

public class Chess extends BoardGame {
  Chess() {
    System.out.println("Chess constructor");

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

} ///:~


Related examples in the same category

1.Combining composition and inheritanceCombining composition and inheritance
2.Inheritance syntax and propertiesInheritance syntax and properties
3.Composition for code reuseComposition for code reuse
4.Cleanup and inheritanceCleanup and inheritance
5.Proper inheritance of an inner classProper inheritance of an inner class
6.Extending an interface with inheritance
7.Inheriting an inner class