Page 455 - Computer science 868 Class 12
P. 455
The output of the preceding program is as follows:
Program 2 A base class Highest is defined to calculate and find the highest number in an array. The class
description is given below.
Class : Highest
Data Members
int a[] : An array of size 10
int h : Stores the highest number in the array
Member Methods
Highest(int x[]) : Parameterised constructor to transfer the contents of array
x[] to array a[]
void findhighest() : Finds the highest number in the array and stores it in h
void display() : Prints the array and the highest number
A derived class SecondH is defined to find the second highest number in the array a[] using
the methods of the base class. The class details is as follows:
Class : SecondH
Data Members
int sh : Stores the second highest number in the array
Member Methods
SecondH(...) : Parameterised constructor to initialise the base class
void findsecond() : Calls findhighest() and then calculates the second highest
number in the array
void display() : Calls display() of both base and derived classes and displays
the array, the highest number and the second highest number
Also write the main method to create object of the derived class and call appropriate methods
to implement the above.
1 class Highest
2 { protected int a[]=new int[10];
3 protected int h;
4 Highest(int x[])
5 { for(int i=0;i<10;i++)
6 { a[i]=x[i];}
7 h=a[0];
8 }
453
Inheritance, Interfaces and Polymorphism 453

