Java MCQ Questions - Operators & Assignments
This section focuses on the "operators and assignments" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. Which of the following can be operands of arithmetic operators?
View Answer
2. Modulus operator, %, can be applied to which of these?
View Answer
3. Decrement operator, −−, decreases the value of variable by what number?
View Answer
4. Which of these statements are incorrect?
View Answer
5. Can 8 byte long data type be automatically type cast to 4 byte float data type?
View Answer
6. Evaluate the value of the expression?
6 - 2 + 10 % 4 + 7
View Answer
7. What is/are highest order precedence operator(s) in Java?
View Answer
8. The && and || operators
View Answer
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?
View Answer
10. Select from among the following character escape code which is not available in Java.
View Answer
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;
}
}
View Answer
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;
}
}
View Answer
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";
}
}
View Answer
14. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
View Answer
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);
}
}
View Answer
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;
View Answer
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);
}
}
View Answer
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);
}
}
View Answer
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 );
}
}
View Answer
20. What is the output of this program?
class increment
{
public static void main(String args[])
{
int g = 5;
System.out.print(++g * 8);
}
}
View Answer
21. What is the output of relational operators?
View Answer
22. Which of these is returned by "greater than", "less than" and "equal to" operators?
View Answer
23. Which of the following operators can operate on a boolean variable?
View Answer
24. Which of these operators can skip evaluating right hand operand?
View Answer
25. Which of these statements is correct?
View Answer
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);
}
}
View Answer
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);
}
}
View Answer
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);
}
}
View Answer
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);
}
}
View Answer
30. Which of these have highest precedence?
View Answer
31. What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3
View Answer
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;
View Answer
33. What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:
View Answer
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);
}
}
View Answer
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);
}
}
View Answer
Also check :
Discussion