📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    The following Java code attempts to demonstrate multiple

    inheritance, which is not directly supported for classes in Java. How can similar functionality be achieved using interfaces? class A {     void methodA() { System.out.println("Method A"); } } class B {     void methodB() { System.out.println("Method B"); } } // class C extends A, B { } // Problematic: Multiple inheritance not allowed public class Main {     public static void main(String[] args) {         // C obj = new C();     } }
    A Change `A` and `B` to interfaces, and `C` to implement both interfaces. Correct Answer Incorrect Answer
    B Use nested classes instead. Correct Answer Incorrect Answer
    C Create a common superclass for `A` and `B`. Correct Answer Incorrect Answer
    D Use composition instead of inheritance. Correct Answer Incorrect Answer
    E Java has no way to achieve this. Correct Answer Incorrect Answer

    Solution

    The correct answer is A

    Practice Next
    ask-question