Multiple inheritance is the ability of a single class to inherit from multiple classes. Java does not have this capability.
The designers of Java considered multiple inheritance to be too complex, and not in line with the goal of keeping Java simple.
Program:
class Base
{
int val;
public void set_val(int i)
{
val=i;
}
}
class A extends Base implements interface1
{
public void show_val()
{
System.out.println("The value of a= "+val);
}
}
class B extends Base implements interface1
{
public void show_val()
{
System.out.println("The value of b= "+val*5);
}
}
class MultipleInherit
{
public static void main(String args[])
{
interface1 obj_A=new A();
interface1 obj_B=new B();
obj_A.set_val(10);
obj_B.set_val(20);
obj_A.show_val();
obj_B.show_val();
}
}
{
int val;
public void set_val(int i)
{
val=i;
}
}
class A extends Base implements interface1
{
public void show_val()
{
System.out.println("The value of a= "+val);
}
}
class B extends Base implements interface1
{
public void show_val()
{
System.out.println("The value of b= "+val*5);
}
}
class MultipleInherit
{
public static void main(String args[])
{
interface1 obj_A=new A();
interface1 obj_B=new B();
obj_A.set_val(10);
obj_B.set_val(20);
obj_A.show_val();
obj_B.show_val();
}
}
No comments:
Post a Comment