|ITEC 120 LAB 21||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 8 MonetaryCoins: 2 quarters, 2 dimes, 2 nickels, and 2 pennies. 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.