Question discussion

What is the output of the following Java program?interface I { default void hi() { System.out.print("I"); } } class A implements I { public…

1583Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Java program?

interface I { default void hi() { System.out.print("I"); } }
class A implements I {
    public void hi() { System.out.print("A"); I.super.hi(); }
}
public class Main {
    public static void main(String[] args) { new A().hi(); }
}
  • AIA
  • BAI
  • CA
  • DI
Correct answer: B

Explanation

A.hi() prints A and then explicitly calls the interface's default method with I.super.hi(), which prints I.

Discussion 0

Nobody has replied yet. Start the discussion!