Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
Java - Interfaces
Consider this code:
interface A {
    static void display() {
        System.out.println("A display");
    }
}
interface B extends A {
    static void display() {
        System.out.println("B display");
    }
}
public class Test {
    public static void main(String[] args) {
        A.display();
        B.display();
    }
}

What is the output?
ACompilation error due to method conflict
BB display A display
CA display B display
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand static methods in interfaces

    Static methods are not inherited; each interface has its own method.
  2. Step 2: Analyze calls

    A.display() calls A's method; B.display() calls B's method.
  3. Step 3: Determine output

    Prints "A display" then "B display" in order.
  4. Final Answer:

    A display B display -> Option C
  5. Quick Check:

    Static methods not inherited; call interface directly [OK]
Quick Trick: Static interface methods are separate per interface [OK]
Common Mistakes:
  • Assuming static methods are inherited
  • Expecting method conflict error
  • Confusing static with default methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes