Categories
Class 12

Record and Highest Inheritance ISC 2019 Theory

A super class Record contains names and marks of the students in two different single dimensional arrays. Define a sub-class Highest to display the names of the students obtaining the highest mark.

The details of the members of both the classes are given below:

Class name: Record
Data members/instance variables:
n[]: array to store names.
m[]: array to store marks.
size: to store the number of students.
Member functions/methods:
Record(int cap): parameterized constructor to initialize the data member size = cap.
void readArray(): to enter elements in both the arrays.
void display(): displays the array elements.

Class name: Highest
Data members/instance variables:
ind: to store the index.
Member functions/methods:
Highest(…): parameterized constructor to initialize the data members of both the classes.
void find(): finds the index of the student obtaining the highest mark and assign it to ‘ind’.
void display(): displays the array elements along with the names and marks of the students who have obtained the highest mark.

Assume that the super class Record has been defined. Using the concept of inheritance, specify the class Highest giving the details of the constructor, void find() and void display().

The super class, main() function and algorithm need not be written.

class Highest extends Record{
    protected int ind;
    public Highest(int c){
        super(c);
        ind = 0;
    }
    public void find(){
        int max = m[0];
        for(int i = 1; i < m.length; i++){
            if(max < m[i]){
                max = m[i];
                ind = i;
            }
        }
    }
    public void display(){
        super.display();
        System.out.println("Highest Marks Details:");
        System.out.println("Student name: " + n[ind]);
        System.out.println("Student marks: " + m[ind]);
    }
}

Leave a Reply