007-002-014

Object Creation: Reference Assignment

Medium

Problem Description

Object Creation: Reference Assignment

Learning Objective: Understand object reference assignment and sharing

Overview

Create a program that verifies multiple variables can reference the same object.

Specifications

  • Create a Counter class (count: int field)
  • increment() method increases count by 1
  • Create an object and reference it with two variables
  • Increment using one, verify result with both

Output Format

c1.count: 1
c2.count: 1
Same object: true

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?