You are on page 1of 4

INHERITANCE PROGRAM

R.P. Lallith Aditya


XII C

Super class:
import java.util.*;

public class Record

String name[];

int rnk[];

int l=5;

Record()

name = new String[l];

rnk = new int[l];

void readValues()

Scanner sc = new Scanner(System.in);

System.out.printf("Enter the names of %d students\n",l);

for(int i=0;i<l;i++)

System.out.print("Enter "+ (i+1) +"th student's name : ");

name[i]=sc.next();

System.out.print("Enter "+(i+1)+" th student's rank : ");


rnk[i]=sc.nextInt();

System.out.println();

void display()

for(int i=0;i<l;i++)

System.out.println("Student's name : "+name[i]);

System.out.println("Student's rank : "+rnk[i]);

System.out.println();

Sub Class:
import java.util.*;

public class Rank extends Record

int index;

public Rank()

super();

index=0;
}

public void highest()

int max=super.rnk[0];

for(int i=1;i<l;i++)

if (max > super.rnk[i])

max = super.rnk[i];

index=i;

public void display()

super.display();

System.out.println();

System.out.println("Student with the highest rank is :


"+name[index]);

System.out.println("Highest rank = "+rnk[index]);

public static void main(String args[])

Rank rk = new Rank();

rk.readValues();
rk.highest();

rk.display();

Output:

You might also like