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.


What operator is used in Java to show equality between two variables?

  1. =

  2. ==

  3. ===

  4. !=

The correct answer is: ==

In Java, the == operator is used to check for equality between two variables. This means that it will return true if the two variables store the same value, and false if they do not. Option A, the = operator, is used to assign a value to a variable. Option C, the === operator, is not a valid operator in Java and should not be used. Option D, the != operator, checks for inequality between two variables, meaning it will return true if the variables store different values and false if they store the same value. Therefore, it is also not the correct operator to use in this scenario.