ITEC 120 LAB 25 Back to Lab index page

Inheritance and Overriding methods

Download the Coin class: Coin.java

Derive a new class from the Coin class, called MonetaryCoin. Store a value in MonetaryCoin which represents its value, and add a method which returns that value.

The toString method should be overridden.

Write a driver which instantiantes 4 MonetaryCoins: 1 quarter, 1 dime, 1 nickel, and 1 penny. Flip all the coins, and report the value of all heads coins and the value of all tails coins. The driver will demonstrate that a MonetaryCoin inherits its parent's ability to be flipped as well as it's parent's isHeads method.