Click to See Complete Forum and Search --> : polymorphism,code reuse and inheritance???


bahcoach
01-13-2005, 10:04 AM
A leturer has been teaching a class C1 with 20 students. In order to keep a record of the students and their work, the lecturer has developed a java program that maintains the students number, full student name and student mark. The lecturer has developed a Class with methods to deal with his class.

The methods perform the following operations:
- print student records in alphabetical order
- Given the student number, print the full student record
- Find the average mark for the class
- Print the student record with the highest mark

The lecturer has been asked to teach an additional class C2 with 10 students. The lecturer has decided to take advantage of the OO feature of the existing program to provide the same operations listed above when the two classes C1 and C2 are combined.

how do i take advantage of inheritance to implement such a java program??

mikeBarr81
01-14-2005, 12:58 PM
From the sound of it you dont need inheritance for this. Inheritance involves moving from abstract to more concrete. For example you may have a vehicle class that has method for moving and stopping, then extend this to a car class which inherits the move and stop methods and does something appropriate to a car.

In your situation, both the classes are identicle in that they have a teacher, a number of students, and methods that do exactly the same thing. All you need to do is make a different object for the other class the teacher is teaching.