Anda di halaman 1dari 4

Page No.

71

Ex no: INTERFACES:MULTIPLE INHERITANCE Date: AIM : To write the program for multiple inheritance by using java. ALGORITHM:

1. Start the program. 2. Class name is Student then, declare the instant variable. 3. Put method is defined by rollno. 4. Class test extends by student class. 5. Install are declared as part1 and part2. 6. m1 and m2 are assigned to part1 and part2. 7. It shows the mark part1 and part2. 8. Sports are included, extends the result class by inheriting test and sports. 9. It prints the sports. 10.Void display method. Display the total number and marks are called by corresponding function
call.

11.Main function calls the corresponding methods. 12.It displays the output. 13.Stop the program.

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

72

PROGRAM: class Student { int rollnumber; void getnumber(int n) { rollnumber=n; } void putnumber() { System.out.println("Rollnumber:"+rollnumber); } } class test extends Student { float part1,part2; void getmarks(float m1,float m2) { part1=m1; part2=m2; } void putmarks() { System.out.println("Marks obtained:"); System.out.println("part1="+part1); System.out.println("part2="+part2); } } interface sports { float sportwt=6.0f; void putwt(); }

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

73

class results extends test implements sports { float total; public void putwt() { System.out.println("sportwt:"+sportwt); } void display() { total=part1+part2+sportwt; putnumber(); putmarks(); putwt(); System.out.println("total score:"+total); } } class hybrid { public static void main(String args[]) { results student1= new results(); student1.getnumber(12); student1.getmarks(27.5f,33.0f); student1.display(); } }

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

74

RESULT: Thus the java program for multiple inheritances has been executed and verified successfully.

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Anda mungkin juga menyukai