Multiple choice technology programming languages

Following code will result in: class A { public static void main(String [] args) {B b = new A(); }} class B extends A {}

  1. Compile error

  2. Runtime Exception

  3. No error

  4. Compile error. Type mismatch: cannot convert from A to B

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

Class B extends Class A, meaning B is a subclass of A. Since a parent class instance cannot be directly assigned to a child class reference without an explicit cast (which would fail at runtime anyway), the code produces a compile-time type mismatch error.