Implementation of Hybrid inheritance in Java with the help of INTERFACE
CODE>>
class Student
{
int rollNumber;
void getNumber(int n)
{
rollNumber=n;
}
void putNumber()
{
System.out.println("Roll No :: "+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\n");
System.out.println("PART1: "+part1);
System.out.println("PART2: "+part2);
}
}
interface Sports
{
float sportWt=6.0F;
void putwt();
}
class Results extends Test implements Sports
{
float total;
public void putwt()
{
System.out.println("Sports Wt="+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(1234);
student1.getMarks(17.4F, 33.0F);
student1.display();
}
}
Comments
Post a Comment