A question bank for every class and subject

Practice questions, with answers and explanations included

794 questions available

Refine

All questions

794 results
521

A method that returns the value of a private data member is called a:

MCQ Easy
a. Setter method
b. Getter method
c. Constructor
d. Static method
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Getter method
Explanation: A getter method returns the value of a data member, providing controlled read access to private data.
522

What is the purpose of the setEnabled() method for a jButton?

SHORT Easy
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: The setEnabled() method enables or disables the button, controlling whether the user can interact with it, using syntax: <button-name>.setEnabled(boolean b);
523

Convert: 2 Bytes = ______ MB (Hint: use the conversion chain).

SHORT Hard
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: 2 Bytes = 2 x 1024^2 MB = 2097152 MB.
524

A method that allows controlled modification of a private data member's value (possibly with validation) is called a:

MCQ Easy
a. Getter method
b. Setter method
c. Constructor
d. Access modifier
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Setter method
Explanation: A setter method sets/modifies a data member's value, and can include validation logic (e.g., rejecting a price below a minimum).
525

Differentiate between jTextField and jTextArea, and between jComboBox and jList.

LONG Medium
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: jTextField allows entry/display of only a single line of text, whereas jTextArea allows multiline input/output and automatically adds scroll bars when needed. jComboBox is a drop-down box from which a user selects one option by clicking the drop-down arrow, whereas jList provides a scrollable list of items from which one or more items may be selected at once.
526

Convert: 3 Bytes = ______ MB (Hint: use the conversion chain).

SHORT Hard
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: 3 Bytes = 3 x 1024^2 MB = 3145728 MB.
527

What is the main benefit of using getter and setter methods instead of allowing direct public access to data members?

MCQ Medium
a. It makes the code shorter
b. It allows validation/control over how the data member's value is changed
c. It makes the class run faster
d. It removes the need for a constructor
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
It allows validation/control over how the data member's value is changed
Explanation: Getter/setter methods allow controlled access — e.g., a setter can validate that a new price isn't below a minimum before allowing the change, which direct public access would not enforce.
528

Which Java data type would be most appropriate to store a person's age (a small whole number)?

MCQ Medium
a. byte
b. double
c. String
d. char
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
byte
Explanation: byte (1 byte, range -128 to 127) is suitable for small integer values like age; using it appropriately saves memory.
529

Write an SQL query to display PrName and UnitPrice of products with unit price above 25000 from table GYM.

SHORT Medium
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: SELECT PrName, UnitPrice FROM GYM WHERE UnitPrice > 25000;
530

Once a data member is declared private, it can still be accessed directly from outside the class using the dot operator.

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
FALSE
Explanation: Private members cannot be accessed directly from outside the class; they require public getter/setter methods for controlled access.
531

Which data type is used in Java to store a single character, enclosed in single quotes?

MCQ Easy
a. String
b. char
c. byte
d. boolean
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
char
Explanation: The char data type stores a single character and its value is enclosed within single quotes, e.g., 'A'.
532

Write an SQL query to display PrName and UnitPrice of products with unit price between 15000 and 25000 from table GYM.

SHORT Medium
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: SELECT PrName, UnitPrice FROM GYM WHERE UnitPrice BETWEEN 15000 AND 25000;
533

A constructor is called explicitly by the programmer using a special 'construct' statement.

TRUE FALSE Medium
a. TRUE
b. FALSE
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
FALSE
Explanation: A constructor is invoked automatically whenever a new object of the class is created (using 'new'); it is never called explicitly by name.
534

What is the storage size of the 'int' data type in Java?

MCQ Medium
a. 1 byte
b. 2 bytes
c. 4 bytes
d. 8 bytes
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
4 bytes
Explanation: The int data type occupies 4 bytes (32 bits) and stores whole numbers in the range -2^31 to +(2^31 - 1).
535

Write an SQL query to display PrName and UnitPrice of products manufactured by 'Fit Express' from table GYM.

SHORT Medium
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: SELECT PrName, UnitPrice FROM GYM WHERE Manufacturer = 'Fit Express';
536

What is the difference between a Class and an Object? Give an example.

SHORT Easy
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: A Class is a template/blueprint defining data members and method members (e.g., class Book with Title, Author, Price). An Object is an instance of that class holding actual data (e.g., book1 with Title='Game of Thrones', Author='George R Martin', Price=450).
537

Which operator is used to test whether two values are equal in Java?

MCQ Easy
a. =
b. ==
c. !=
d. ===
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
==
Explanation: The relational operator == tests whether two values are equal; a single '=' is the assignment operator.
538

Write an SQL query to display PrName and UnitPrice of products whose manufacturer name starts with 'A' from table GYM.

SHORT Medium
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
Explanation: SELECT PrName, UnitPrice FROM GYM WHERE Manufacturer LIKE 'A%';
539

Why is a constructor used in a class?

SHORT Easy
Information Technology (802) · Class 12 · Sep 26, 2026
Show answer
Explanation: A constructor is used to initialize the data members of a class (or perform other initialization) automatically whenever a new object of the class is created.
540

Which logical operator returns true only if BOTH connected conditions are true?

MCQ Easy
a. ||
b. &&
c. !
d. ^
Information Technology (802) · Class 11 · Sep 26, 2026
Show answer
&&
Explanation: The && (AND) logical operator returns true only when both conditions it connects are true.