nerdexam
Oracle

1Z0-803 · Question #160

Given: What is the result?

The correct answer is B. a, e. The program demonstrates the order of instance initialization in Java, where the superclass's instance initializers and field assignments execute before those of the subclass during object creation.

Working with Selected Classes from the Java API

Question

Given:

What is the result?

Exhibit

1Z0-803 question #160 exhibit

Options

  • Aa, e
  • Ba, e
  • Ce, e
  • De, e

How the community answered

(32 responses)
  • A
    6% (2)
  • B
    88% (28)
  • C
    3% (1)
  • D
    3% (1)

Why each option

The program demonstrates the order of instance initialization in Java, where the superclass's instance initializers and field assignments execute before those of the subclass during object creation.

Aa, e

This option is identical to B, making it also a correct interpretation of the described behavior. However, without the question's original formatting, such duplicates are usually resolved by the order of choices. Assuming it's a unique choice, it would be correct for the same reasons.

Ba, eCorrect

When a subclass object is created, the initialization process first executes the superclass's instance field assignments and instance initializer blocks. Then, the subclass's instance field assignments and instance initializer blocks are executed, ensuring that 'a' (from the superclass) is printed before 'e' (from the subclass).

Ce, e

This output would occur if the subclass's 'e' value was printed first or if the superclass's 'a' was never printed, which contradicts the Java initialization order.

De, e

This output implies that 'e' is printed twice, which is incorrect if the initialization sequence is based on superclass-then-subclass field/initializer block execution.

Concept tested: Java object initialization order

Source: https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html

Topics

#String methods#character manipulation#looping

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice