24a - w12 - MCQ - Final
24a - w12 - MCQ - Final
PROGRAMMING IN JAVA
Assignment 12
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10
QUESTION 1:
using JDBC program will return a ResultSet object. This object is:
c. All records in verba m from the table but those records with null values.
d. All records in verba m from the table but those records are not with null values.
Correct Answer:
When executing an SQL SELECT query using JDBC, the result is returned as a ResultSet object. This
ResultSet object contains all the records (rows) returned by the SELECT query from the specified table
(myTable in this case), without any filtering based on null values. Therefore, option b is correct.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 2:
Which of the following method is used to set a frame, f with size 300 × 200 pixels?
JFrame f = newJFrame();
a. f.setSize(300, 200);
b. f.setSize(200, 300);
c. f.paint(300, 200);
d. f.setVisible(300, 200);
Correct Answer:
a. f.setSize(300, 200);
The method setSize(int width, int height) is used to set the size of a JFrame (or any
component) in Java Swing. Therefore, op on a is the correct answer to set a JFrame named f with size
300 × 200 pixels.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
System.out.println(str.length());
}
}
a. 38
b. 39
c. 40
d. 41
Correct Answer:
b. 39
The provided Java program calculates and prints the length of the string str, which contains the text
"NPTEL ‐ Programming in JAVA ‐ JULY 2024".
The output of this program will be: 39
This is because the string "NPTEL ‐ Programming in JAVA ‐ JULY 2024" consists of 39 characters, including
spaces and hyphens.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 4:
a. finally
b. excep on finished
d. Compila on fails
Correct Answer:
The program is syntac cally correct and here for two try blocks, there is one catch block.
Here's the step‐by‐step explana on:
QUESTION 5:
class Program {
public static void main(String[] args) {
int counter = 10;
do {
System.out.print(2 / counter);
counter--;
} while (counter > 2);
}
}
a. 00000012
b. 00000000
c. 10011001
d. 12211221
Correct Answer:
b. 00000000
The provided program uses a do‐while loop to iterate from counter = 10 down to counter = 3. During
each itera on, it prints the result of 2 / counter.
1. counter = 10: 2 / 10 results in 0 (integer division).
2. counter = 9: 2 / 9 results in 0.
3. counter = 8: 2 / 8 results in 0.
4. counter = 7: 2 / 7 results in 0.
5. counter = 6: 2 / 6 results in 0.
6. counter = 5: 2 / 5 results in 0.
7. counter = 4: 2 / 4 results in 0.
When counter = 3: 8. 2 / 3 results in 0.
A er counter becomes 2, the loop condi on counter > 2 fails, and the loop terminates.
Therefore, the output of the program is 00000000.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 6:
What should be the value of X and Y for the output of the below program to be 36?
a. X = 6 and Y = 5
b. X = 2 and Y = 7
c. X = 1 and Y = 10
d. X = 4 and Y = 5
Correct Answer:
d. X = 4 and Y = 5
The following is the output of the program for different values of X and Y:
QUESTION 7:
Which of the following options correctly initializes the elements of the numbers array with values 1, 2,
3, 4, and 5?
Correct Answer:
numbers = new int[]{1, 2, 3, 4, 5}; is the correct answer because it ini alizes the
numbers array with values 1, 2, 3, 4, and 5 using array ini alizer syntax.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 8:
Which of the following statements are correct and would NOT cause a compilation error?
a. iii, iv, v, vi
b. i, ii, iii, iv
c. ii, iii, v, vi
d. i, ii, iv, vi
Correct Answer:
a. iii, iv, v, vi
Op on iii, iv, v and vi are syntac cally correct for declara on of an array.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 9:
a. true false
b. false true
c. true true
d. false false
Correct Answer:
a. true false
str1 and str2 are string literals and will be interned to the same memory loca on, so str1 ==
str2 will be true. However, str3 is created using the new keyword, so it will be stored in a different
memory loca on, leading str1 == str3 to be false.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 10:
a. Compila on ERROR
d. Run me ERROR
Correct Answer:
The division by zero will throw an ArithmeticException, which will be caught in the catch block.
Then, the finally block will be executed.