CIS 2168 - Homework 1

Handed out: 08/31/10
Due: by 10pm on 09/06/10

Assignment 1: Data Members and Inheritance [plagiarised from Dr. Lakaemper]

This assignment deals with the topics of static data members as well as inheritance.

Please design 3 classes:
class 1: 'Mammal'
class 2: 'Feline', which extends 'Mammal'
class 3: 'Lion', which extends 'Feline'

The constructor of each of these classes should print out the number of instances of that class created up to that point. Note that since Lion is a Feline, ech instance of Lion is an instance of Feline. In turn each instance of Feline is an instance of Mammal. Thus when an instanc eof Lion is created we might get a printout that says that this is the 3rd Lion, 8th Feline, and 13th Mammal.

Each class contains the method

    public void getMe();

This method should print how many instances of that class were created at the time of creation of that instance.

After you designed and implemented the classes that way, create a main program (in class 'Homework1'). Create an array of 15 Mammals. Fill the array with 5 instances of each class. Then in a loop invoke getMe on each element of the array. The result should be a printout of 45 sentences, hopefully giving correct information about the objects.