Object Oriented Programming: Unit II: Inheritance, Packages and Interfaces

Multiple Inheritance

Definition, Concept, Syntax, Implementation, Example Java Programs

Multiple inheritance is a mechanism in which the child class inherits the properties from more than one parent classes.

Multiple Inheritance

Definition: Multiple inheritance is a mechanism in which the child class inherits the properties from more than one parent classes.

For example

Java does not support multiple inheritance because it creates ambiguity when the properties from both the parent classes are inherited in child class or derived class. But it is supported in case of interface because there is no ambiguity as implementation is provided by the implementation class.

• Implementation

interface A

{

void display1

}

interface B

{

void display2();

}

class C implements A,B

{

public void display1()

{

System.out.println("From Interface A");

}

public void display2()

{

System.out.println("From Interface B");

}

public static void main(String args[])

{

C obj = new C();

obj.display1();

obj.display2();

}

Output

From Interface A

From Interface B

Program Explanation:

In above program, we have created both the parent interfaces and the derived class is using method declared ion the parent interface. Note that the definition of these methods is present in the child class. Thus multiple inheritance is achieved with the help of interface.

Object Oriented Programming: Unit II: Inheritance, Packages and Interfaces : Tag: : Definition, Concept, Syntax, Implementation, Example Java Programs - Multiple Inheritance