CIS 17: Java Programming
Project D
Objective:
To investigate inheritance and polymorphism.
Inheritance
All of the following classes may be placed in the same file.
- Create a class called Amphibian.
- Add two methods, moveInWater() and moveOnLand() that announce themselves.
- From Amphibian, inherit a class called Frog. Do not define any methods in this class.
- Create a public class named FrogTest. In main(), create a Frog, upcast it to Amphibian and demonstrate that all the methods work.
Polymorphism
Now, test for polymorphic behavior:
- Modify your Frog class so that it overrides the method definitions from the base class (provides new definitions using the same method signatures).
- The methods should identify the object as a Frog.
- Name your classes Amphibian2, Frog2 and FrogTest2.
- Note what happens in main(). Did the behavior change?
Submit your work via the CATE form for Project D.
Legend: method/function keyword literal/identifier
2007/03/12