x

Java Operator and Assignments Questions

PREV     NEXT

Java Operator and Assignments Questions:


  1. In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.
    1. The line labeled 1.
    2. The line labeled 2.
    3. The line labeled 3.
    4. The line labeled 4.
    5. All the lines are correct and the program compiles.
  2. Which of these assignments are valid. Select the four correct answers.
    1. short s = 28;
    2. float f = 2.3;
    3. double d = 2.3;
    4. int I = ‘1’;
    5. byte b = 12;
  3. What gets printed when the following program is compiled and run. Select the one correct answer.
    1. 0
    2. 1
    3. 2
    4. 3
  4. Which of these lines will compile? Select the four correct answers.
    1. short s = 20;
    2. byte b = 128;
    3. char c = 32;
    4. double d = 1.4;;
    5. float f = 1.4;
    6. byte e = 0;
  5. The signed right shift operator in Java is –. Select the one correct answer.
    1. <<;
    2. >>
    3. >>>;
    4. None of these.
  6. What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
    1. 0
    2. 1
    3. 2
    4. 3
  7. What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
    1. 0
    2. 1
    3. 2
    4. 3
  8. What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
    1. 0
    2. 1
    3. 2
    4. 3
  9. What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
    1. 0
    2. 1
    3. 2
    4. 3
  10. Which operator is used to perform bitwise inversion in Java. Select the one correct answer.
    1. ~
    2. !
    3. &
    4. |
    5. ^
  11. What gets printed when the following program is compiled and run. Select the one correct answer.
    1. 3
    2. 0
    3. 1
    4. 11
    5. 252
    6. 214
    7. 124
    8. -4
  12. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 7 1
    2. 3 7
    3. 1 7
    4. 3 1
    5. 1 3
    6. 7 3
    7. 7 5
  13. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 1 3
    2. 3 5
    3. 5 1
    4. 3 6
    5. 1 7
    6. 1 5
  14. Which operator is used to perform bitwise exclusive or.
    1. &
    2. ^
    3. |
    4. !
    5. ~
  15. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 1
    2. 2
    3. 3
    4. 4
  16. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 1
    2. 2
    3. 3
    4. 4
  17. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 5
    2. 2
    3. 80
    4. 0
    5. 64
  18. What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
    1. 1
    2. 0
    3. 7
    4. 5
    5. 23
    6. 2147483646
  19. Which of the following are correct. Select all correct answers.
    1. Java provides two operators to do left shift – << and <<<.
    2. >> is the zero fill right shift operator.
    3. >>> is the signed right shift operator.
    4. For positive numbers, results of operators >> and >>> are same.
  20. What is the result of compiling and running the following program. Select one correct answer.
    1. 63
    2. -1
    3. 0
    4. 1
    5. 127
    6. 128
    7. 255
  21. What all gets printed when the following gets compiled and run. Select the two correct answers.
    1. 0
    2. 1
    3. 2
    4. 3
    5. 4
  22. What happens when the following class is compiled and run. Select one correct answer.
    1. The program prints 0
    2. The program prints 1
    3. The program prints 2
    4. The program prints 3
    5. The program does not compile because of problems in the if statement.
  23. Which all lines are part of the output when the following code is compiled and run. Select the nine correct answers.
    1. 0 0
    2. 0 1
    3. 0 2
    4. 0 3
    5. 1 0
    6. 1 1
    7. 1 2
    8. 1 3
    9. 2 0
    10. 2 1
    11. 2 2
    12. 2 3
    13. 3 0
    14. 3 1
    15. 3 2
    16. 3 3
    17. The program does not print anything.
  24. Which all lines are part of the output when the following code is compiled and run. Select the one correct answer.
    1. 0 0
    2. 0 1
    3. 0 2
    4. 0 3
    5. 1 0
    6. 1 1
    7. 1 2
    8. 1 3
    9. 2 0
    10. 2 1
    11. 2 2
    12. 2 3
    13. 3 0
    14. 3 1
    15. 3 2
    16. 3 3
    17. The program does not print anything.
  25. Which all lines are part of the output when the following code is compiled and run. Select the six correct answers.
    1. 0 0
    2. 0 1
    3. 0 2
    4. 0 3
    5. 1 0
    6. 1 1
    7. 1 2
    8. 1 3
    9. 2 0
    10. 2 1
    11. 2 2
    12. 2 3
    13. 3 0
    14. 3 1
    15. 3 2
    16. 3 3
  26. Which all lines are part of the output when the following code is compiled and run. Select the six correct answers.
    1. 0 0
    2. 0 1
    3. 0 2
    4. 0 3
    5. 1 0
    6. 1 1
    7. 1 2
    8. 1 3
    9. 2 0
    10. 2 1
    11. 2 2
    12. 2 3
    13. 3 0
    14. 3 1
    15. 3 2
    16. 3 3
  27. Which all lines are part of the output when the following code is compiled and run. Select the three correct answers.
    1. 0 0
    2. 0 1
    3. 0 2
    4. 0 3
    5. 1 0
    6. 1 1
    7. 1 2
    8. 1 3
    9. 2 0
    10. 2 1
    11. 2 2
    12. 2 3
    13. 3 0
    14. 3 1
    15. 3 2
    16. 3 3

Answers to questions on Operators and Assignments


  1. c. It is not possible to assign an integer to a character in this case without a cast.
  2. a, c, d, e. 2.3 is of type double. So it cannot be assigned to a float without a cast.
  3. b
  4. a, c, d, f. If RHS (Right hand side) is an integer within the correct range of LHS (Left hand side), and if LHS is char, byte, or short, no cast is required. A decimal number is a double by default. Assigning it to float requires a cast.
  5. b
  6. b. In the second assignment to variable b, the expression (i+=2) does not get evaluated.
  7. d
  8. c
  9. d
  10. a
  11. h
  12. c
  13. f
  14. b
  15. a
  16. d
  17. d
  18. f
  19. d
  20. b
  21. a, c
  22. e. The expression in the if statement must evaluate to a boolean.
  23. b, c, d, e, g, h, i, j, l
  24. q
  25. b, c, d, g, h, l
  26. b, c, d, g, h, l
  27. b, c, d

PREV     NEXT



Like it? Please Spread the word!

Post Your Thoughts