Multiple choice technology programming languages

class A{ public void _a(){ System.out.println("A"); } } class B extends A{ public void _a(){ System.out.println("B"); } } public class InheritanceTest { public static void main(String[] args){ A aa = new B(); System.out.println(aa._a()); } } What is the output?

  1. B

  2. A

  3. Compilation fails

  4. none of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Compilation fails because _a() returns void, but System.out.println(aa._a()) attempts to print a void return value. Void methods cannot be used in print statements - they must be called separately. The code would compile if _a() returned a value or if the print statement didn't try to capture the return.