Operators and Assignments in Java MCQs

@T-Bone

This question paper focuses on the "Operators and Assignments" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

This question paper focuses on the "Operators and Assignments" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

Questions

1. Which of the following can be operands of arithmetic operators?

Mark the correct option

2. Modulus operator, %, can be applied to which of these?

Mark the correct option

3. Decrement operator, −−, decreases the value of variable by what number?

Mark the correct option

4. Which of these statements are incorrect?

Mark the correct option

5. Can 8 byte long data type be automatically type cast to 4 byte float data type?

Mark the correct option

6. Evaluate the value of the expression? 6 - 2 + 10 % 4 + 7

Mark the correct option

7. What is/are highest order precedence operator(s) in Java?

Mark the correct option

8. The && and || operators

Mark the correct option

9. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

Mark the correct option

10. Select from among the following character escape code which is not available in Java.

Mark the correct option

11. What will be the output of the program? class Main { public static void main(String [] args) { Main p = new Main(); p.start(); } void start() { long [] a1 = {3,4,5}; long [] a2 = fix(a1); System.out.print(a1[0] + a1[1] + a1[2] + " "); System.out.println(a2[0] + a2[1] + a2[2]); } long [] fix(long [] a3) { a3[1] = 7; return a3; } }

Mark the correct option

12. What will be the output of the program? class Main { public static void main(String [] args) { Main p = new Main(); p.start(); } void start() { boolean b1 = false; boolean b2 = fix(b1); System.out.println(b1 + " " + b2); } boolean fix(boolean b1) { b1 = true; return b1; } }

Mark the correct option

13. What will be the output of the program? class Main { public static void main(String [] args) { Main p = new Main(); p.start(); } void start() { String s1 = "s"; String s2 = fix(s1); System.out.println(s1 + " " + s2); } String fix(String s1) { s1 = s1 + "st"; System.out.print(s1 + " "); return "st"; } }

Mark the correct option

14. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?

Mark the correct option

15. Predict the output of following Java Program? class Test { public static void main(String args[]) { int x = -4; System.out.println(x>>1); int y = 4; System.out.println(y>>1); } }

Mark the correct option

16. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? 1. x++; 2. x = x + 1; 3. x += 1; 4. x =+ 1;

Mark the correct option

17. What is the output of this program? class Main { public static void main(String args[]) { double var1 = 2 + 4; double var2 = var1 / 4; int var3 = 2 + 4; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } }

Mark the correct option

18. What will be the output of the program? class Main { public static void main(String [] args) { int x=20; String sup = (x < 15) ? "s" : (x < 22)? "t" : "h"; System.out.println(sup); } }

Mark the correct option

19. What will be the output of the program? class Bitwise { public static void main(String [] args) { int x = 11 & 9; int y = x ^ 3; System.out.println( y | 12 ); } }

Mark the correct option

20. What is the output of this program? class increment { public static void main(String args[]) { int g = 5; System.out.print(++g * 8); } }

Mark the correct option

21. What is the output of relational operators?

Mark the correct option

22. Which of these is returned by "greater than", "less than" and "equal to" operators?

Mark the correct option

23. Which of the following operators can operate on a boolean variable?

Mark the correct option

24. Which of these operators can skip evaluating right hand operand?

Mark the correct option

25. Which of these statements is correct?

Mark the correct option

26. What is the output of this program? class Relational_operator { public static void main(String args[]) { int var1 = 5; int var2 = 6; System.out.print(var1 > var2); } }

Mark the correct option

27. What is the output of this program? class ternary_operator { public static void main(String args[]) { int x = 3; int y = ~ x; int z; z = x > y ? x : y; System.out.print(z); } }

Mark the correct option

28. What is the output of this program? class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } }

Mark the correct option

29. What is the output of this program? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } }

Mark the correct option

30. Which of these have highest precedence?

Mark the correct option

31. What should be expression1 evaluate to in using ternary operator as in this line? expression1 ? expression2 : expression3

Mark the correct option

32. What is the value stored in x in following lines of code? int x, y, z; x = 0; y = 1; x = y = z = 8;

Mark the correct option

33. What is the order of precedence (highest to lowest) of following operators? 1. & 2. ^ 3. ?:

Mark the correct option

34. What is the output of this program? class operators { public static void main(String args[]) { int var1 = 5; int var2 = 6; int var3; var3 = ++ var2 * var1 / var2 + var2; System.out.print(var3); } }

Mark the correct option

35. What is the output of this program? class Main { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } }

Mark the correct option