Classes/Objects  «Prev  Next»


Java Operators - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 

1. What value is assigned to x as the result of executing the following code?

int y = 3;
y++;
x = y++;

Please select the best answer.
  A. 3
  B. 4
  C. 5
  D. 6

2. What is the difference between >> and >>>?
Please select the best answer.
  A. The >> operator shifts left and the >>> operator shifts right.
  B. The >> operator shifts right and the >>> operator shifts left.
  C. The >> operator fills the shifted out high order bits based on the sign bit and the >>> operator fills the high order bits with zeros.
  D. The >>> operator fills the shifted out high order bits based on the sign bit and the >> operator fills the high order bits with zeros.

3. Which of the following is true?
Please select the best answer.
  A. The && operator is equivalent to &2.
  B. The && operator is equivalent to &*2.
  C. The && operator always evaluates both operands.
  D. The && operator does not evaluate its second operand if the value of the first operand is false.

4. Which of the following statements about numeric promotion are true?
Please select all the correct answers.
  A. Numeric promotion is sometimes used with boolean values.
  B. Numeric promotion is sometimes used with object references.
  C. Numeric promotion is sometimes used with byte values.
  D. Numeric promotion is sometimes used with int values.

5. Which expressions are always true for the following code?
String s = "123"; 
String t = new String("123");

Please select all the correct answers.
  A. s.equals(t)
  B. t.equals(s)
  C. t == s
  D. s == t

6. Which expressions are always true for the following code?
String  s = new String("true");
boolean t = true;


Please select all the correct answers.
  A. s.equals(""+t)
  B. t.equals(s)
  C. t == s
  D. s == ""+t