Class 12

Information Technology (802)

351 questions available

Refine

All questions

351 results
141

Java provides which two statements for conditional (selection) execution of code?

MCQ Easy
a. for and while
b. if-else and switch
c. try and catch
d. class and object
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
if-else and switch
Explanation: Java provides the if-else statement and the switch statement for executing code conditionally.
142

In an if statement with only ONE statement in its body, are curly braces mandatory?

MCQ Medium
a. Yes, always mandatory
b. No, they are optional
c. Only for switch statements
d. Only in loops
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
No, they are optional
Explanation: If there is only one statement in the block following if, the curly braces are optional (though good practice suggests using them).
143

In the code: if(percentage >= 40) { System.out.println("PASSED"); } else { System.out.println("FAILED"); } — what is displayed if percentage = 35?

MCQ Easy
a. PASSED
b. FAILED
c. Nothing is displayed
d. Compile error
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
FAILED
Explanation: Since 35 is not >= 40, the condition is false, so the else block executes, displaying FAILED.
144

Which combination of if-else and logical operator correctly checks if percentage is between 40 (inclusive) and 60 (exclusive) for Second Division?

MCQ Medium
a. if (percentage >= 40 || percentage < 60)
b. if (percentage >= 40 && percentage < 60)
c. if (percentage > 40 && percentage <= 60)
d. if (percentage = 40)
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
if (percentage >= 40 && percentage < 60)
Explanation: The && (logical AND) operator combines two conditions that must BOTH be true: percentage >= 40 AND percentage < 60.
145

An if-else statement placed within another if or else statement is called:

MCQ Easy
a. A recursive if
b. A nested if-else
c. A cascading switch
d. An infinite if
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
A nested if-else
Explanation: A nested if-else statement is one if-else placed within another if or else block.
146

The switch statement's expression must evaluate to which of the following data types?

MCQ Medium
a. float or double only
b. byte, short, int, or char
c. boolean only
d. String only (in this version)
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
byte, short, int, or char
Explanation: The expression in a Java switch statement must evaluate to byte, short, int, or char.
147

In a switch statement, what does the 'break' statement after each case group do?

MCQ Easy
a. Ends the entire program
b. Terminates the switch and continues execution after the switch block
c. Restarts the switch from the top
d. Causes an infinite loop
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Terminates the switch and continues execution after the switch block
Explanation: The break statement terminates the switch statement and causes execution to continue with statements after the switch.
148

In a switch statement, if the expression does not match any case constant, which block executes?

MCQ Easy
a. The first case block
b. The last case block
c. The default block
d. No block executes and an error occurs
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
The default block
Explanation: If there's no match for any case, the statements in the default block are executed.
149

Which loop structure evaluates its test condition BEFORE executing the loop body (entry-controlled loop)?

MCQ Easy
a. do-while loop
b. while loop
c. Both do the same
d. for loop only executes once
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
while loop
Explanation: The while loop tests the condition before executing the body, making it an entry-controlled loop.
150

Which loop structure is guaranteed to execute its body AT LEAST ONCE, regardless of the test condition?

MCQ Easy
a. while loop
b. do-while loop
c. for loop
d. if statement
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
do-while loop
Explanation: The do-while loop is exit-controlled — it evaluates the test condition AFTER executing the body, so the body executes at least once.
151

If int number = 6; and the loop is: while(number<=5){...}, how many times does the loop body execute?

MCQ Medium
a. Zero times
b. Once
c. Five times
d. Six times
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Zero times
Explanation: Since 6 is not <= 5, the while loop's condition is false from the start, so the body never executes (zero times).
152

If int number = 6; and the loop is: do{...}while(number<=5);, how many times does the loop body execute?

MCQ Medium
a. Zero times
b. At least once (exactly once here)
c. Five times
d. It causes a compile error
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
At least once (exactly once here)
Explanation: Since a do-while loop tests AFTER executing, the body executes once (printing for number=6) before the condition (6<=5, false) exits the loop.
153

A loop that never terminates because its test condition is always true is called:

MCQ Easy
a. A nested loop
b. An infinite loop
c. A finite loop
d. A dead loop
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
An infinite loop
Explanation: An infinite loop occurs when the test condition is always true, so the loop body executes forever.
154

What is the error in this code: int x = 1; while (x <= 5); { x = x + 1; }

MCQ Hard
a. Missing semicolon after while condition
b. A semicolon placed after the while condition, making the loop body an empty (null) statement, causing an infinite loop
c. x is not declared
d. The condition uses the wrong operator
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
A semicolon placed after the while condition, making the loop body an empty (null) statement, causing an infinite loop
Explanation: Placing a semicolon right after the while(condition) makes the loop body a null (empty) statement; since x never changes inside the actual while, this results in an infinite loop.
155

How many parts of a for loop are separated by semicolons?

MCQ Easy
a. Two
b. Three
c. Four
d. One
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Three
Explanation: A for loop has three parts separated by semicolons: initialization, test condition, and the update/step, e.g., for(int i=0; i<5; i++).
156

How many times does this loop execute: for(int count=1; count<5; count++) { ... }

MCQ Medium
a. 3
b. 4
c. 5
d. 6
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
4
Explanation: The loop runs for count = 1,2,3,4 — a total of 4 times (it exits when count becomes 5, since 5<5 is false). This is an example of an 'off by one' consideration.
157

What is wrong with the loop: for(int count=5; count<=1; count++) { ... }

MCQ Medium
a. It runs infinitely
b. The body never executes, since the initial value (5) already exceeds the limit (1) with a positive increment
c. It causes a syntax error
d. It runs exactly once
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
The body never executes, since the initial value (5) already exceeds the limit (1) with a positive increment
Explanation: Since the initial value 5 is already greater than the limit 1, and the increment is positive, the test condition (5<=1) is false from the start, so the loop body never executes.
158

What is the scope of a loop counter declared within a for loop statement, e.g., for(int count=1; ...)?

MCQ Medium
a. Available throughout the entire program
b. Available only within the body of the for loop
c. Available only in the main method
d. Available globally after the loop ends
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Available only within the body of the for loop
Explanation: A variable declared within a for loop's initialization is scoped only to the loop body and is NOT visible outside the loop.
159

Placing a semicolon at the end of a for statement, e.g., for(int count=1; count<=5; count++);, causes:

MCQ Hard
a. A compile-time error
b. The loop body to be treated as empty, executing only once after the loop terminates
c. The loop to run forever
d. No effect at all
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
The loop body to be treated as empty, executing only once after the loop terminates
Explanation: The semicolon creates an empty loop body (does nothing 5 times); the block that follows in curly braces then executes just once, after the loop terminates — not the intended behavior.
160

The switch statement in Java can evaluate an expression of type float.

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
FALSE
Explanation: The switch expression must evaluate to byte, short, int, or char — not float or double.