1.
What is the output of the following code?
int x = 10;
if (x > 5)
System.out.println("A");
else
System.out.println("B");
A) A
B) B
C) No output
D) Compilation error
Answer: A
2.
Which of the following is a valid selection statement in Java?
A) if
B) switch
C) if-else
D) All of the above
Answer: D
3.
What will be the output?
int a = 5;
if (a == 5);
System.out.println("Hello");
A) Hello
B) No output
C) Compilation error
D) Runtime error
Answer: A (semicolon after if makes condition ineffective, so "Hello" always
prints)
4.
Which of the following data types cannot be used in a switch statement in Java
(before Java 7)?
A) int
B) char
C) String
D) byte
Answer: C (String allowed from Java 7 onwards)
5.
What will be the output?
int num = 2;
switch(num) {
case 1: System.out.println("One");
case 2: System.out.println("Two");
case 3: System.out.println("Three");
}
A) Two
B) Two Three
C) One Two Three
D) Compilation error
Answer: B (No break → fall through)
6.
Which keyword is used to exit from a switch case block?
A) exit
B) continue
C) break
D) stop
Answer: C
7.
What is the output of the following code?
int x = 3;
if (x > 5)
System.out.println("Big");
else if (x == 3)
System.out.println("Equal");
else
System.out.println("Small");
A) Big
B) Equal
C) Small
D) No output
Answer: B
8.
In a switch statement, what happens if no break is used in cases?
A) Only the matched case runs
B) All cases after the matched case run
C) Compiler error
D) Only default case runs
Answer: B
9.
Which of the following is true about if statement in Java?
A) The condition must be a boolean expression
B) The condition can be int or float
C) The condition can be 1 for true and 0 for false
D) None of these
Answer: A
10.
What is the output of the following code?
char grade = 'B';
switch (grade) {
case 'A': System.out.println("Excellent");
break;
case 'B': System.out.println("Good");
break;
default : System.out.println("Average");
}
A) Excellent
B) Good
C) Average
D) Compilation error
Answer: B
11.
Which of the following selection statements allow multiple branching?
A) if-else
B) switch
C) Both A and B
D) None
Answer: C
12.
What will be the output?
int x = 10, y = 20;
if (x > y)
System.out.println("X");
else
if (x < y)
System.out.println("Y");
else
System.out.println("Equal");
A) X
B) Y
C) Equal
D) No output
Answer: B
Would you like me to also convert these into AIKEN format (so you can directly
import into Moodle/quiz tools)?