Recall & Review
beginner
What is multiple inheritance in Java?
Multiple inheritance means a class can inherit features from more than one parent class or interface. In Java, multiple inheritance is supported only through interfaces, not classes.Click to reveal answer
beginner
How do interfaces enable multiple inheritance in Java?
A Java class can implement multiple interfaces. This allows the class to inherit abstract methods from many sources, achieving multiple inheritance without the problems of inheriting from multiple classes.Click to reveal answer
beginner
Can a Java class extend multiple classes?No, Java does not allow a class to extend more than one class to avoid complexity and ambiguity. Instead, Java uses interfaces to allow multiple inheritance.Click to reveal answer
intermediate
What happens if two interfaces have methods with the same signature and a class implements both?The class must provide its own implementation of the method. This resolves any ambiguity because the class decides how to implement the shared method.Click to reveal answer
beginner
Example: How to declare a class that implements two interfaces named InterfaceA and InterfaceB?public class MyClass implements InterfaceA, InterfaceB {
// Implement all abstract methods from InterfaceA and InterfaceB here
}Click to reveal answer
Which keyword is used in Java to inherit from multiple interfaces?
✗ Incorrect
In Java, a class uses the 'implements' keyword to inherit from one or more interfaces.
Can a Java class extend two classes at the same time?
✗ Incorrect
Java does not allow a class to extend more than one class to avoid ambiguity.
If two interfaces have the same method signature, what must the implementing class do?
✗ Incorrect
The class must implement the method once, resolving the conflict.
Which of these is a benefit of using interfaces for multiple inheritance?
✗ Incorrect
Interfaces avoid the diamond problem because they only contain abstract methods without state.
How do you declare a class named 'Car' that implements interfaces 'Engine' and 'Wheels'?
✗ Incorrect
The correct syntax uses 'implements' followed by the interface names separated by commas.
Explain how Java supports multiple inheritance using interfaces and why it does not allow multiple inheritance with classes.
Think about how interfaces differ from classes and why Java designers chose this approach.
You got /4 concepts.
Describe what happens when a class implements two interfaces that have a method with the same name and signature.
Consider how the class resolves method conflicts from interfaces.
You got /3 concepts.