CSC 175 Home Page
Dr. D. Chays
406 Science
(516)877-4479
Quiz 1 topics (mid-Feb)
Tutoring
- hw5, hw6 and the project may be handed in (with no late penalty) up to the start of the final exam (10:30am May 14).
- Reminders re: collaboration: lab exercises may be done individually or in groups of two (pair programming).
To receive credit, hand in your own work; even if it is not complete, you will at least get partial credit.
The project builds upon lab exercises and so may be done in groups of two; no sharing of code between groups. If you work in a group, hand in one copy with both names on it.
- Another example of Polymorphism: PolymorphicJungle.jar (which you may extract with 7zip).
In this program, Lion extends Animal, and overrides saySomething method.
The Driver calls addAnimal to add an Animal object and a Lion object into the same array named animals,
and the makeSounds method of Jungle calls saySomething on each object without specifying which saySomething method to call.
At runtime: depending on whether it is a Lion or Animal it calls the saySomething method defined in Lion or Animal class (respectively)
via polymorphism (meaning of operation determined at runtime).
See PolymorphicJungleV2.jar (version 2 of this program) which has an interface JungleInterface
that is implemented by Jungle and Jungle1, which differ only in the data structure they use to store animals (an ArrayList vs an array); note that if you change one word in Driver by changing Jungle to Jungle1 (thus calling the constructor of a different class that implements the same interface), you get the same output;
in other words, the driver code is independent of the underlying implementation of the Jungle ADT; it just calls upon the methods of the Jungle ADT as specified in JungleInterface.