Multiple choice technology programming languages

Given: class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?

  1. Compilation fails.

  2. TestB

  3. TestA

  4. An exception is thrown at runtime

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

This demonstrates Java's dynamic method dispatch (polymorphism). Even though the object is cast to TestA type, the actual object is a TestB instance. At runtime, JVM calls the overridden method in the actual object type (TestB), not the reference type (TestA). The start() method in TestB executes, printing 'TestB'.