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

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

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

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.