Page 492 - Computer science 868 Class 12
P. 492
9. A superclass Record contains names and marks of the students in two different single dimensional arrays. Define a subclass
Highest to display the names of the students obtaining the highest mark. The details of the members of both classes are given
below. [ISC 2019]
Class name : Record
Data Members
n[] : Array to store names
m[] : Array to store marks
size : to store the number of students
Member Methods
Record(int cap) : parameterised constructor to initialise 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
ind : to store the index
Member Methods
Highest(…) : parameterised constructor to initialise 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 superclass 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 superclass, main function and algorithm need NOT be written.
Ans. import java.util.*;
class Record
{
protected String n[];
protected int m[],size;
Record(int cap)
{ size=cap;
n=new String[size];
m=new int[size];
}
void readarray()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter "+size+" names and marks");
for(int i=0;i<size;i++)
{ n[i]=sc.next();
m[i]=sc.nextInt();
}
}
void display()
{
for(int i=0;i<size;i++)
System.out.println(n[i]+"\t"+m[i]);
}
}
class Highest extends Record
{
int ind;
490490 Touchpad Computer Science-XII

