Multiple Inheritances does not
support by Java directly. Multiple
Inheritances enables to derive a class from multiple parent classes.
Let A and B are parent classes and
C is the derived class
Java
provides Interface approach to support the concept of Multiple
Inheritance. A class can also implements
multiple interfaces.
Example:
class Test
{
int
sub1,sub2,sub3;
void
readdata1(int x,int y,int z)
{
sub1=x;
sub2=y;
sub3=z;
}
void
printdata1()
{
System.out.println("sub1
marks="+sub1);
System.out.println("sub2
marks="+sub2);
System.out.println("sub3
marks="+sub3);
}
}
interface Sports
{
int
smarks=55;
public
void printdata2();
}
class Result extends Test
implements Sports
{
int
sum;
public
void printdata2()
{
printdata1();
sum=sub1+sub2+sub3+smarks;
System.out.println("Total
Marks="+sum);
}
}
class mul
{
public
static void main(String[] args)
{
Result
obj=new Result();
obj.readdata1(35,67,89);
obj.printdata2();
}
}
No comments:
Post a Comment