[go: up one dir, main page]

0% found this document useful (0 votes)
33 views2 pages

P11T2

The document describes a program that uses multilevel inheritance. The Student class sets and displays student name and number. The Marks class extends Student, sets and displays marks for two subjects, and calculates the total marks. The FinalTotal class extends Marks and displays the final total marks calculated by adding the individual subject marks. The main method creates an object of FinalTotal class, sets the student name and roll number, sets the subject marks, and calls methods to display the student details, marks, and final total.

Uploaded by

Nagesh Parab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

P11T2

The document describes a program that uses multilevel inheritance. The Student class sets and displays student name and number. The Marks class extends Student, sets and displays marks for two subjects, and calculates the total marks. The FinalTotal class extends Marks and displays the final total marks calculated by adding the individual subject marks. The main method creates an object of FinalTotal class, sets the student name and roll number, sets the subject marks, and calls methods to display the student details, marks, and final total.

Uploaded by

Nagesh Parab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name :- Nagesh Parab

Roll no.:- 07

Q.2]. Marks extends the class student and Final total extends marks. Student has methods
for setting and displaying student number and name. Marks has method for setting and
displaying marks of two subjects. Final total has methods for calculating and displaying final
total. Write a program for above problem statement using multilevel inheritance.
Program :-
class student
{
public String name=null;
public int rn=0;
void get_data_s(String sname,int sroll)
{
name=sname;
rn=sroll;
}
void display_s()
{
System.out.println("Student Name : "+name+"\nRoll No. : "+rn);
}
}
class Marks extends student
{
public int marks_m=0;
public int marks_p=0;
void set_marks(int m,int p)
{
marks_m=m;
marks_p=p;
}
void display_m()
{
System.out.println("Maths : "+marks_m+"\nPhysics : "+marks_p);
}
}
class FinalTotal extends Marks
{
void Finaltotal()
{
int total=marks_m+marks_p;
System.out.println("Total Marks For 2 Subjects : "+total);
}
}
Name :- Nagesh Parab
Roll no.:- 07

class INPUT
{
public static void main(String[] args)
{
FinalTotal obj=new FinalTotal();
obj.get_data_s("Nagesh",7);
obj.set_marks(85,96);
obj.display_s();
obj.display_m();
obj.Finaltotal();
}
}

You might also like