Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


If 'a' is an object and 'b' is an object and you assign 'a = b;' in Java, and then modify 'a', what happens to 'b'?

  1. It is modified as well

  2. It remains unchanged

  3. It is nullified

  4. It gets a copy of modifications made to 'a'

The correct answer is: It is modified as well

When we assign 'a = b;' in Java and then modify 'a', 'b' is also modified because both 'a' and 'b' are referencing the same object. Therefore, any changes made to 'a' will also be reflected in 'b'. Option B is incorrect because 'b' is not a copy of 'a' but rather a reference to the same object. Option C is incorrect because the assignment of 'a' to 'b' does not nullify 'b' in any way. Option D is incorrect because 'b' does not get a copy of modifications made to 'a', but rather the original modifications themselves.