nerdexam
Oracle

1Z0-803 · Question #33

Given: What is the reference type of myZ and what is the type of the object it references?

The correct answer is C. Reference type is Z; object type is Y.. This question assesses the understanding of polymorphism in object-oriented programming by distinguishing between the declared type of a reference variable (reference type) and the actual type of the object it points to (object type).

Working with Inheritance

Question

Given:

What is the reference type of myZ and what is the type of the object it references?

Exhibit

1Z0-803 question #33 exhibit

Options

  • AReference type is Z; object type is Z.
  • BReference type is Y; object type is Y.
  • CReference type is Z; object type is Y.
  • DReference type is X; object type is Z.

How the community answered

(25 responses)
  • A
    12% (3)
  • B
    4% (1)
  • C
    80% (20)
  • D
    4% (1)

Why each option

This question assesses the understanding of polymorphism in object-oriented programming by distinguishing between the declared type of a reference variable (reference type) and the actual type of the object it points to (object type).

AReference type is Z; object type is Z.

This option would be correct if `myZ` referred to an object of type `Z`, for example, if the code was `Z myZ = new Z();`.

BReference type is Y; object type is Y.

This option would be correct if the variable was declared as type `Y` and referenced an object of type `Y`, such as `Y myY = new Y();`.

CReference type is Z; object type is Y.Correct

The reference type is the declared type of the variable `myZ`, which is `Z`. The object type is the actual class of the instance being referenced, which is `Y`. This is a fundamental concept of polymorphism, where a supertype reference (`Z`) can point to a subtype object (`Y`), assuming `Y` extends or implements `Z`.

DReference type is X; object type is Z.

This option is incorrect because it misidentifies both the reference type as `X` and the object type as `Z`, which does not align with the most common polymorphic scenarios that yield the correct answer C.

Concept tested: Object-oriented polymorphism and type identification

Source: https://docs.oracle.com/javase/tutorial/java/concepts/polymorphism.html

Topics

#polymorphism#reference types#object types#inheritance

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice