Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Easy

Question 52

Which is not a valid statement based on the given code?


class A {}

class B extends A {}


  • A

    B b = new A();

  • B

    B b = new B();

  • C

    A a = new B();

  • D

    A a = new A();

Reveal correct answer

Correct answer: A

Explanation

B b = new A(); -> A child class reference cannot refer to a parent class object. This will give a compilation error. A a = new B(); -> A parent class reference can refer to a child class object. This is polymorphism. B b = new B(); -> No issues at all. A a = new A(); -> No issues at all.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need