polymorphism,code reuse and inheritance???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: polymorphism,code reuse and inheritance???

  1. #1
    Join Date
    Jan 2005
    Posts
    7

    Unhappy polymorphism,code reuse and inheritance???

    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??
    bahcoach

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center