InterviewSolution
Saved Bookmarks
| 1. |
Why multiple inheritance is not supported in Java? |
|
Answer» A key part of object-oriented PROGRAMMING is MULTIPLE inheritance. This means that a class inherits the properties of multiple classes. However, multiple inheritance may lead to many problems. Some of these are:
The above problems are one of the reasons that Java doesn't support multiple inheritance. A PROGRAM that demonstrates the diamond problem in Java is given as follows: PUBLIC class A { void display() { System.out.println("This is class A"); } } public class B extends A { void display() { System.out.println("This is class B"); } } public class C extends A { void display() { System.out.println("This is class C"); } } public class D extends B, C { public static void main(String args[]) { D obj = new D(); D.display(); } }The above program leads to an error as multiple inheritance is not allowed Java. |
|