Counting created objects and current references

A booking program executes the following Java code from top to bottom. Assume Ticket is available and each new Ticket() expression completes successfully, creating one fresh object. Count only the objects created by the expressions shown.


Java
Ticket first = new Ticket();
Ticket second = new Ticket();
Ticket third = first;
// Checkpoint A

first = second;
// Checkpoint B

second = new Ticket();
// Checkpoint C

third = first;
// Checkpoint D


At each checkpoint, enter two exact whole-number counts: the total number of objects created so far, and the number of distinct objects referenced by first, second, and third together. Count an object only once in the second column even if several variables refer to it.

CheckpointObjects created so farDistinct objects referenced
A
B
C
D

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors