Multiple choice technology programming languages

Class Y is a subclass of Class X.Will this compile? Y myY=new Y(); X myX=myY;

  1. No

  2. Compile Error

  3. Yes

  4. Runtime Error

  5. Not Sure

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

Since Class Y is a subclass of Class X, an instance of Y can be implicitly upcast to a reference of type X. This is a fundamental polymorphic assignment in Java and compiles successfully.