Ch8
Ch8
published by Prentice
Hall
Java, Java, Java
Object Oriented Problem Solving
• Introduction
• Java’s Inheritance Mechanism
• Abstract Classes, Interfaces, and
Polymorphism
• Example: A Toggle Button
• Example: The Cipher Class Hierarchy
• Case Study: A Two-Player Game Hierarchy
• Principles of Object-Oriented Design
Java, Java, Java, 3E by R. Morelli | R. Walde Copyright 2006. Chapter 8: Inheritance
Introduction
• Chapter 0: Class inheritance in a hierarchy
of animals and chess pieces.
• Chapter 3: The toString() method is
inherited from the Object class.
• Chapter 4: Inheritance in Java’s AWT and
Swing class hierarchies.
• In this chapter we take a closer look at the
mechanisms behind these concepts.
Superclass
Subclass
• But all objects are printed using print(Object o) which (likely) uses
polymorphism and dynamic binding:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
} // Transpose
Player 2 is a NimPlayer
Sticks left: 11 Who's turn: Player 1
Human is player 1 and
You can pick up between 1 and 3 : 3 computer is player 2.
Sticks left: 8 Who's turn: Player 2 NimPlayer takes 3 sticks.