Write a Java Program for MULTIPLE INHERITANCE
import java.io.*;
class student
{
int rn;
void getNumber(int n)
{
rn = n;
}
void putNumber()
{
System.out.println("Roll
Number: " +rn);
}
}
class test extends student
{
float pt1,
pt2;
void getMarks(float m1,
float m2)
{
pt1 = m1;
pt2 = m2;
}
void putMarks()
{
System.out.println("<Marks Obtained>");
System.out.println("Maths: " +pt1);
System.out.println("Science: " +pt2);
}
}
interface sports
{
float spts =
6.0F;
void
putWt();
}
class result extends test implements sports
{
float total;
public void
putWt()
{
System.out.println("Sports Weight: " +spts);
}
void display()
{
total = pt1+pt2+spts;
putNumber();
putMarks();
putWt();
System.out.println("Total score: " +total);
}
}
public class multinheri
{
public static void
main(String[] args)throws Exception
{
result stud1 = new
result();
BufferedReader bf = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the roll number: ");
int num =
Integer.parseInt(bf.readLine());
stud1.getNumber(num);
System.out.println("Enter the marks in Maths: ");
int ma =
Integer.parseInt(bf.readLine());
System.out.println("Enter the marks in Science: ");
int sc = Integer.parseInt(bf.readLine());
stud1.getMarks(ma,sc);
stud1.display();
}
}
OUTPUT
C:\Program Files\Java\jdk1.5.0\bin>java multinheri
Enter the roll number:
45
Enter the marks in Maths:
58
Enter the marks in Science:
45
Roll Number: 45
<Marks Obtained>
Maths: 58.0
Science: 45.0
Sports Weight: 6.0
Total score: 109.0
No comments:
Write comments