233k views
5 votes
Which of the following is not possible? A class that implements two interfaces. A class that inherits from two classes. A class that inherits from one class, and implements an interface. All of these are possible.

1 Answer

2 votes

Answer:

"A class that inherits from two classes"

Step-by-step explanation:

If we're talking about Java, you can't extend from two classes. The reason for this is Java doesn't allow multiple inheritance.

The reason for this is to avoid the ambiguity caused by it. One of the cases where multiple inheritance can cause ambiguity is the diamond problem.

Diamond problem can occur if two classes (say B and C) inherit from one class (say A). And another class (say D) inherits from both B & C.

If B and C class override the same method from A class. And D class calls that method, which one will be called, class B's or C's??

User Blissweb
by
6.4k points