Multiple choice technology programming languages

class B1{ public B1(){ System.out.println("B"); } } class A1 extends B1{ void A1(){ System.out.println("A"); } } public class Test { public static void main(String[] args){ B1 a = new A1(); } } what will be output?

  1. A

  2. B

  3. BA

  4. AB

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

Instantiating A1 invokes the superclass constructor B1() which outputs 'B'. The subclass method void A1() looks like a constructor but is a regular method due to its void return type, meaning it is not executed during class instantiation.