Question bank

Class 12

1 subject · 351 questions

Refine

All questions

351 results
161

A do-while loop always runs at least once, even if the test condition is initially false.

TRUE FALSE Easy
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
TRUE
Explanation: Because the do-while loop tests its condition after executing the body, it always runs at least once.
162

In a for loop, you can use the comma operator to include multiple initialization/update expressions, e.g., for(x=0,y=10; x<10; x++,y--).

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
TRUE
Explanation: The comma operator allows multiple items in the initialization and update parts of a for loop.
163

Differentiate between a while loop and a do-while loop (name at least two differences).

SHORT Medium
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: A while loop is entry-controlled (tests the condition before running the loop body) and may run zero or more times. A do-while loop is exit-controlled (tests the condition after running the body) and runs at least once. Also, in a do-while loop, the test condition variables need not be initialized before entering the loop, unlike a while loop.
164

Write the Java syntax for the if-else, switch, while, do-while, and for statements.

LONG Medium
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: if-else: if(expression) { statements } else { statements } switch: switch(expression) { case constant1: statements; break; ... default: statements; break; } while: while(expression) { statements } do-while: do { statements } while(expression); for: for(initial_value; test_condition; change_counter) { statements }
165

An array in Java is used to:

MCQ Easy
a. Store only a single value
b. Hold a list of values of the same data type
c. Define a class
d. Handle exceptions
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Hold a list of values of the same data type
Explanation: An array is a variable that can hold more than one value (a list of values) of the same data type.
166

In Java, array indices start from:

MCQ Easy
a. 1
b. 0
c. -1
d. It depends on the array size
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
0
Explanation: Array indices in Java start from 0 and go up to n-1 for an array of size n.
167

For an array declared as double[] marks = new double[5];, what is the valid range of index values?

MCQ Easy
a. 1 to 5
b. 0 to 4
c. 0 to 5
d. 1 to 4
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
0 to 4
Explanation: For an array of size 5, valid indices range from 0 to 4 (n-1).
168

Which property of an array gives its size (number of elements)?

MCQ Easy
a. size
b. length
c. count
d. capacity
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
length
Explanation: The length property of an array gives its size, e.g., marks.length.
169

What exception is thrown when an array is accessed using an index outside its valid range?

MCQ Medium
a. NullPointerException
b. ArrayIndexOutOfBoundsException
c. ArithmeticException
d. ClassCastException
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
ArrayIndexOutOfBoundsException
Explanation: Accessing an array with an invalid index (e.g., index=5 for an array of size 5) throws an ArrayIndexOutOfBoundsException.
170

A method in Java is best described as:

MCQ Easy
a. A single variable
b. A block of statements grouped together to perform a specific task
c. A data type
d. A comment
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
A block of statements grouped together to perform a specific task
Explanation: A method is a block of statements grouped together to perform a specific task, having a name, return type, optional parameters, and a body.
171

Which return type is used for a method that does NOT return any value?

MCQ Easy
a. int
b. void
c. null
d. empty
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
void
Explanation: The void return type is used for methods that do not return any value.
172

What does the 'static' modifier allow, when applied to a method?

MCQ Medium
a. The method to be called without creating an invoking object
b. The method to always return zero
c. The method to run only once ever
d. The method to be private
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
The method to be called without creating an invoking object
Explanation: The static modifier allows a method to be called without needing an invoking object (i.e., it can be called directly using the class name or from within the same class).
173

In a method call, the values supplied are copied into the method's:

MCQ Easy
a. Return statement
b. Parameters
c. Class name
d. Comments
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Parameters
Explanation: The arguments supplied in a method call are copied into the method's corresponding parameters.
174

Array indices in Java range from 0 to n, where n is the size of the array.

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
FALSE
Explanation: Array indices range from 0 to n-1 for an array of size n, not 0 to n; using index n would cause an ArrayIndexOutOfBoundsException.
175

A method's parameter list acts like regular local variables within the method body.

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
TRUE
Explanation: Parameters behave like local variables scoped to the method body, receiving copies of the arguments passed during the call.
176

How do you declare and initialize an array of 5 doubles named 'marks' with size specified separately from declaration?

SHORT Easy
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: double[] marks; marks = new double[5]; (or in one line: double[] marks = new double[5];)
177

Write the syntax structure of a user-defined method in Java.

SHORT Medium
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: return_type method_name(list of parameters separated by commas) { statements; return statement; }
178

Write a static Java method 'rectangle_area' that takes length and breadth (both double) as parameters and returns the area of the rectangle. Also show how to call it from main and store the result.

LONG Medium
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: static double rectangle_area(double length, double breadth) { return (length * breadth); } To call it: double a = rectangle_area(45.5, 78.5); System.out.println("Area of the rectangle = "+a);
179

In Object Oriented Programming, a program is viewed as:

MCQ Easy
a. A single sequence of instructions
b. A collection of objects that interact with each other to solve a problem
c. A set of only global variables
d. A single function
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
A collection of objects that interact with each other to solve a problem
Explanation: In OOP, a program is a collection of objects that interact with each other to solve a problem; each object is an instance of a class.
180

A class is best described as:

MCQ Easy
a. An instance of an object
b. A physical or logical entity having certain attributes (a template for creating objects)
c. A single value stored in memory
d. A loop construct
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
A physical or logical entity having certain attributes (a template for creating objects)
Explanation: A class is a template/blueprint (a physical or logical entity with attributes) from which objects are created.