InterviewSolution
Saved Bookmarks
| 1. |
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:Class name: Record Data member/instance variable: 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 elementsClass name: Highest Data member/instance variable: ind: to store the index Member functions/methods: Highest(…): parameterized constructor to initialize the data members of both the classesvoid 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 markAssume 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. |
|
Answer» class Record { protected String n[]; protected int m[]; protected int size; public Recordfint cap) { } public void readarray() { } public void display() { } } class Highest extends Record { private int ind; public Highest(int cap) { super(cap) } public void find() { ind = 0; for (int i = 0; i < size; i++) { if(m[i]>m[ind]){ ind = i; } } } public void display() { super.display(); System.out.println("Highest marks are::" +m[ind]); System.out.println("Students who score the highest marks are::"); for (int i = 0; i < size; i++) } if(m[i] == m[ind]) { System.out.println(n[i]); } } } } |
|