Multiple choice technology programming languages

What is the result of the following code? 1. public abstract class A { 2. private void doStuff() { 3. System.out.println("A"); 4. } 5. 6. public static void main(String [] args) { 7. A a = new B(); 8. a.doStuff(); 9. } 10. } 11. 12. class B extends A { 13. protected void doStuff() { 14. System.out.println("B"); 15. } 16. }

  1. A

  2. B

  3. Compiler error on line 7

  4. Compiler error on line 13

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

In Java, private methods cannot be overridden. The doStuff() method in A is private, so it is invisible to subclasses. When a.doStuff() is called, the compiler resolves it directly to the private method in class A because the reference type is A. Thus, it prints 'A' without dynamic dispatch to B.doStuff(), which is a completely independent method.