PREV NEXT
Java Operator and Assignments Questions:
- In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.
- The line labeled 1.
- The line labeled 2.
- The line labeled 3.
- The line labeled 4.
- All the lines are correct and the program compiles.
- Which of these assignments are valid. Select the four correct answers.
- short s = 28;
- float f = 2.3;
- double d = 2.3;
- int I = ‘1’;
- byte b = 12;
- What gets printed when the following program is compiled and run. Select the one correct answer.
- 0
- 1
- 2
- 3
- Which of these lines will compile? Select the four correct answers.
- short s = 20;
- byte b = 128;
- char c = 32;
- double d = 1.4;;
- float f = 1.4;
- byte e = 0;
- The signed right shift operator in Java is –. Select the one correct answer.
- <<;
- >>
- >>>;
- None of these.
- What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
- 0
- 1
- 2
- 3
- What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
- 0
- 1
- 2
- 3
- What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
- 0
- 1
- 2
- 3
- What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.
- 0
- 1
- 2
- 3
- Which operator is used to perform bitwise inversion in Java. Select the one correct answer.
- ~
- !
- &
- |
- ^
- What gets printed when the following program is compiled and run. Select the one correct answer.
- 3
- 0
- 1
- 11
- 252
- 214
- 124
- -4
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 7 1
- 3 7
- 1 7
- 3 1
- 1 3
- 7 3
- 7 5
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 1 3
- 3 5
- 5 1
- 3 6
- 1 7
- 1 5
- Which operator is used to perform bitwise exclusive or.
- &
- ^
- |
- !
- ~
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 1
- 2
- 3
- 4
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 1
- 2
- 3
- 4
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 5
- 2
- 80
- 0
- 64
- What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
- 1
- 0
- 7
- 5
- 23
- 2147483646
- Which of the following are correct. Select all correct answers.
- Java provides two operators to do left shift – << and <<<.
- >> is the zero fill right shift operator.
- >>> is the signed right shift operator.
- For positive numbers, results of operators >> and >>> are same.
- What is the result of compiling and running the following program. Select one correct answer.
- 63
- -1
- 0
- 1
- 127
- 128
- 255
- What all gets printed when the following gets compiled and run. Select the two correct answers.
- 0
- 1
- 2
- 3
- 4
- What happens when the following class is compiled and run. Select one correct answer.
- The program prints 0
- The program prints 1
- The program prints 2
- The program prints 3
- The program does not compile because of problems in the if statement.
- Which all lines are part of the output when the following code is compiled and run. Select the nine correct answers.
- 0 0
- 0 1
- 0 2
- 0 3
- 1 0
- 1 1
- 1 2
- 1 3
- 2 0
- 2 1
- 2 2
- 2 3
- 3 0
- 3 1
- 3 2
- 3 3
- The program does not print anything.
- Which all lines are part of the output when the following code is compiled and run. Select the one correct answer.
- 0 0
- 0 1
- 0 2
- 0 3
- 1 0
- 1 1
- 1 2
- 1 3
- 2 0
- 2 1
- 2 2
- 2 3
- 3 0
- 3 1
- 3 2
- 3 3
- The program does not print anything.
- Which all lines are part of the output when the following code is compiled and run. Select the six correct answers.
- 0 0
- 0 1
- 0 2
- 0 3
- 1 0
- 1 1
- 1 2
- 1 3
- 2 0
- 2 1
- 2 2
- 2 3
- 3 0
- 3 1
- 3 2
- 3 3
- Which all lines are part of the output when the following code is compiled and run. Select the six correct answers.
- 0 0
- 0 1
- 0 2
- 0 3
- 1 0
- 1 1
- 1 2
- 1 3
- 2 0
- 2 1
- 2 2
- 2 3
- 3 0
- 3 1
- 3 2
- 3 3
- Which all lines are part of the output when the following code is compiled and run. Select the three correct answers.
- 0 0
- 0 1
- 0 2
- 0 3
- 1 0
- 1 1
- 1 2
- 1 3
- 2 0
- 2 1
- 2 2
- 2 3
- 3 0
- 3 1
- 3 2
- 3 3
Answers to questions on Operators and Assignments
- c. It is not possible to assign an integer to a character in this case without a cast.
- a, c, d, e. 2.3 is of type double. So it cannot be assigned to a float without a cast.
- b
- 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.
- b
- b. In the second assignment to variable b, the expression (i+=2) does not get evaluated.
- d
- c
- d
- a
- h
- c
- f
- b
- a
- d
- d
- f
- d
- b
- a, c
- e. The expression in the if statement must evaluate to a boolean.
- b, c, d, e, g, h, i, j, l
- q
- b, c, d, g, h, l
- b, c, d, g, h, l
- b, c, d
Post Your Thoughts