Operators

1.What is the difference between == and .equals() in Java?
  • A. == compares object references, while .equals() compares values
  • B. == compares values, while .equals() compares references
  • C. Both work the same way
  • D. .equals() only works for primitive types

== compares object references, while .equals() compares values

== compares object references, while .equals() compares values

2.What will be the output of this bitwise operation?
int a = 5, b = 3; System.out.println(a & b);
  • A. 1
  • B. 3
  • C. 5
  • D. 7

1

1

3. What is the output of the following code?
int x = 10; System.out.println(x++ + ++x);
  • A. 21
  • B. 22
  • C. 23
  • D. Compilation error

22

22

4.Which operator has the highest precedence in Java?
  • A. * (multiplication)
  • B. ++ (increment)
  • C. && (logical AND)
  • D. = (assignment)

++ (increment)

++ (increment)

5.What will be the value of result after executing the following code?
int x = 9; int result = x << 2;
  • A. 16
  • B. 8
  • C. 36
  • D. 25

36

36