Creating and Storing Objects (Instantiation)

AP Computer Science A· difficulty 4/5

a b Object data

After <code>Box a = new Box(); Box b = a;</code>, modifying <code>b</code> (through its methods)

  • A

    Modifies the same object that a refers to

    check_circle
  • B

    Has no effect on a

  • C

    Throws an error

  • D

    Creates a copy

Explanation

<code>b = a;</code> copies the reference, not the object. Both refer to the same Box.

Want 10 more like this — adaptive to your weak spots?

Related questions