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

JPR Practical Assignment 13 Solution

1. The document implements multiple inheritance by creating a Student class with roll number and name attributes, a Test class that extends Student and implements a Sports interface with a static attribute, and displays the student details and test marks. 2. It takes input from the user, creates a Test object, and calls its display1 method to output the student details, test marks, and sports marks. 3. The code implements multiple inheritance by having the Test class extend the Student class and implement the Sports interface.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

JPR Practical Assignment 13 Solution

1. The document implements multiple inheritance by creating a Student class with roll number and name attributes, a Test class that extends Student and implements a Sports interface with a static attribute, and displays the student details and test marks. 2. It takes input from the user, creates a Test object, and calls its display1 method to output the student details, test marks, and sports marks. 3. The code implements multiple inheritance by having the Test class extend the Student class and implement the Sports interface.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

WAP to implement following multiple inheritance :

Class student : Interface sports :

Rollno, name Spmarks=10


Void display()

Class test :

M1, M2
import java.io.*;

interface sports

{ final static int spmarks=10;

class student

{ DataInputStream d=new DataInputStream(System.in);

int rn;

String n;

public void display() throws Exception

{ System.out.println("\nEnter roll no. & name : ");

rn=Integer.parseInt(d.readLine());

n=d.readLine();

System.out.println("\nRoll no. : "+rn);

System.out.println("Name : "+n);

class test extends student implements sports

{ DataInputStream d=new DataInputStream(System.in);

int m1,m2;

public void display1() throws Exception

{ display();

System.out.println("Enter marks of class test 1 : ");

m1=Integer.parseInt(d.readLine());
System.out.println("Enter marks of class test 2 : ");

m2=Integer.parseInt(d.readLine());

System.out.println("Marks of class test 1 : "+m1);

System.out.println("Marks of class test 2 : "+m2);

System.out.println("Sport Marks : "+spmarks);

class p28

{ public static void main(String[] arg) throws Exception

{ DataInputStream d=new DataInputStream(System.in);

test ob1=new test();

ob1.display1();

 Output :

1. WAP to implement following hybrid inheritance :

Class Student :

Rn, n

Class test :

M1 , m2
Class result : Interface sports:

total Spmarks=5
import java.io.*;

interface sports

{ final static int spmarks=5;

class student

{ DataInputStream d=new DataInputStream(System.in);

int rn;

String n;

void display() throws Exception

{ System.out.println("\nEnter roll no. & name : ");

rn=Integer.parseInt(d.readLine());

n=d.readLine();

System.out.println("\nRoll no. : "+rn);

System.out.println("Name : "+n);

class test extends student

{ DataInputStream d=new DataInputStream(System.in);

int m1,m2;

void display1() throws Exception

{ display();

System.out.println("Enter marks of class test 1 : ");

m1=Integer.parseInt(d.readLine());

System.out.println("Enter marks of class test 2 : ");

m2=Integer.parseInt(d.readLine());

System.out.println("Marks of class test 1 : "+m1);

System.out.println("Marks of class test 2 : "+m2);

}
}

class result extends test implements sports

{ DataInputStream d=new DataInputStream(System.in);

int total;

public void display2() throws Exception

{ display1();

total=m1+m2+spmarks;

System.out.println("Total : "+total);

class p28

{ public static void main(String[] arg) throws Exception

{ DataInputStream d=new DataInputStream(System.in);

result ob1=new result();

ob1.display2();

 Output :

You might also like