0% found this document useful (0 votes)
2 views4 pages

Understanding Multiple Inheritance in Java

Uploaded by

khasimshaik00001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Understanding Multiple Inheritance in Java

Uploaded by

khasimshaik00001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Multiple Inheritance in Java

Why Java doesn't support it and how


it's achieved using Interfaces
Why Java Doesn't Support Multiple
Inheritance
1. Diamond Problem:
• Ambiguity arises if two parent classes have the
same method.
• Compiler cannot decide which method to inherit.

2. Simplicity & Maintainability:


• Avoids complexity in the object model.
• Makes code easier to understand and maintain.
How Java Achieves Multiple
Inheritance
• Java supports multiple inheritance using
Interfaces.
• A class can implement multiple interfaces.
• Interfaces provide multiple inheritance of type
(not implementation).
Example: Multiple Inheritance with
Interfaces
interface Printable { void print(); }
interface Showable { void show(); }

class Demo implements Printable, Showable {


public void print() { [Link]("Printing..."); }
public void show() { [Link]("Showing..."); }
}

Output:
Printing...
Showing...

You might also like