nerdexam
Oracle

1Z0-803 · Question #214

Given: How many objects have been created when the line / / do complex stuff is reached?

The correct answer is C. Four. The question asks to count the total number of distinct objects instantiated in a given Java code snippet before a specific line.

Java Basics

Question

Given:

How many objects have been created when the line / / do complex stuff is reached?

Exhibit

1Z0-803 question #214 exhibit

Options

  • ATwo
  • BThree
  • CFour
  • DSix

How the community answered

(40 responses)
  • A
    15% (6)
  • B
    5% (2)
  • C
    73% (29)
  • D
    8% (3)

Why each option

The question asks to count the total number of distinct objects instantiated in a given Java code snippet before a specific line.

ATwo

This would only count the two `Item` objects, ignoring the `String` literal objects created implicitly during instantiation.

BThree

This count would imply only one `String` object was created or an incorrect count of `Item` objects.

CFourCorrect

Four objects are created: two instances of the `Item` class via the `new` operator, and two distinct `String` literal objects ('Book' and 'Pen') that are passed as arguments to the `Item` constructors. The line `Item item3 = item1;` only creates a new reference, not a new object.

DSix

This count would require two additional objects to be instantiated beyond the four objects identified in the correct analysis.

Concept tested: Java object instantiation and String literals

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

Topics

#object creation#String literals#autoboxing

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice