0% found this document useful (0 votes)
19 views

Interface and Inheritance

The document defines classes for a student exam system including a Student class to store student details, a Result class that extends Student and implements an exam interface, and a main method that takes user input for a student's name, ID and marks to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Interface and Inheritance

The document defines classes for a student exam system including a Student class to store student details, a Result class that extends Student and implements an exam interface, and a main method that takes user input for a student's name, ID and marks to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

interface Exam{
void percent_cal();
}

class Student{
public static final int NUM = 5;
String name;
int roll_no;
int mark[] = new int[NUM];

Student(String n, int r, int mrk[]){


name = n;
roll_no = r;
for(int i=0; i<NUM; i++)
mark[i] = mrk[i];
}

void display(){
System.out.println("Register number of student : " + roll_no);
System.out.println("Name of the Student : " + name);
System.out.println("Marks of the Student : ");
for(int i=0; i<NUM; i++)
System.out.println("Mark " + (i+1) + " : " + mark[i]);
}
}

class Result extends Student implements


Exam{ Result(String n, int r, int mk[])
{
super(n, r, mk);
}
public void percent_cal(){
int total = 0;
for(int i=0; i<Student.NUM; i+
+) total += mark[i];
float percent = total / (Student.NUM);
System.out.println("Percentage : " + percent);
}
void display(){
super.display();
}
}
public class MultipleInh{
public static void main(String args[]){
String s;
int rno;
int m[] = new int[Student.NUM];
Scanner read = new
Scanner(System.in);
System.out.println("Enter the name of student : ");
s = read.next();
System.out.println("Enter register number :
"); rno = read.nextInt();
System.out.println("Enter marks : ");
for(int i=0; i<Student.NUM; i++){
System.out.println("Enter mark " + (i+1) + " : ");
m[i] = read.nextInt();
}

Result R = new Result(s, rno, m);


R.display();
R.percent_cal();
}
}
Enter the name of
student : astra
Enter register
number : 0013
Enter marks :
Enter mark 1 :
76
Enter mark 2 :
83
Enter mark 3 :
90
Enter mark 4 :
79
Enter mark 5 :
83
Register number of student :
13 Name of the Student :
astra
Marks of the Student :
Mark 1 : 76
Mark 2 : 83
Mark 3 : 90
Mark 4 : 79
Mark 5 : 83

Percentage : 82.0

You might also like