0% found this document useful (0 votes)
6 views3 pages

Java 20 MCQs Answer Key

The document provides an answer key for a Java multiple-choice questionnaire aimed at 10th standard students, including 20 questions. Each question is followed by the correct answer and a detailed explanation of the reasoning behind it. The content serves as a reference for teachers to assess students' understanding of Java programming concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Java 20 MCQs Answer Key

The document provides an answer key for a Java multiple-choice questionnaire aimed at 10th standard students, including 20 questions. Each question is followed by the correct answer and a detailed explanation of the reasoning behind it. The content serves as a reference for teachers to assess students' understanding of Java programming concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java MCQ – Answer Key

20 Questions | 10th Standard


For Teacher / Reference Use Only

Quick Answer Reference:


[Link] Answer [Link] Answer [Link] Answer
Q1 B Q8 C Q15 D
Q2 C Q9 B Q16 B
Q3 C Q10 D Q17 B
Q4 B Q11 B Q18 B
Q5 B Q12 C Q19 B
Q6 C Q13 B Q20 B
Q7 B Q14 A

Detailed Answer Explanations:


Q1. What is the correct syntax to print output in Java?
Correct Answer: (B) [Link]("Hello");
Explanation: Java uses [Link]() to display output on the screen.

Q2. What will be the output of the following code?


int x = 10, y = 3;
[Link](x % y);
Correct Answer: (C) 1
Explanation: The % operator gives the remainder. 10 divided by 3 = 3 remainder 1.

Q3. Which keyword is used to exit a switch-case block?


Correct Answer: (C) break
Explanation: break terminates the switch-case and prevents fall-through to the next case.

Q4. How many times will the following loop execute?


for(int i = 0; i < 5; i++) {
[Link](i);
}
Correct Answer: (B) 5
Explanation: i goes from 0 to 4 (i < 5), so the loop runs 5 times.

Q5. What will be the output of this code?


int a = 5;
if(a > 3) {
[Link]("Yes");
} else {
[Link]("No");
}
Correct Answer: (B) Yes
Explanation: a = 5 which is greater than 3, so the if block executes and prints 'Yes'.

Q6. Which loop checks the condition AFTER executing the body at least once?
Correct Answer: (C) do-while loop
Explanation: do-while executes the body first, then checks the condition. So it always runs at least once.

Q7. What is the output of the following code?


for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
[Link](i + " ");
}
Correct Answer: (B) 1 2 4 5
Explanation: continue skips iteration when i == 3, so 3 is not printed. All others print normally.

Q8. What does the following code print?


int i = 1;
while(i <= 3) {
[Link](i + " ");
i++;
}
Correct Answer: (C) 1 2 3
Explanation: i starts at 1, increments each time, and stops when i > 3. Prints 1, 2, 3.

Q9. Which of the following correctly declares an integer variable in Java?


Correct Answer: (B) int x = 5;
Explanation: In Java, the keyword int (lowercase) is used to declare integer variables.

Q10. What will be the value of x after this code runs?


int x = 10;
x = x + 5;
x = x * 2;
Correct Answer: (D) 30
Explanation: First x = 10 + 5 = 15. Then x = 15 * 2 = 30.

Q11. What is the output of the following switch-case?


int n = 2;
switch(n) {
case 1: [Link]("One");
case 2: [Link]("Two");
case 3: [Link]("Three");
}
Correct Answer: (B) Two Three
Explanation: There are no break statements, so fall-through occurs. case 2 and case 3 both execute.

Q12. Which operator is used to check if two values are EQUAL in Java?
Correct Answer: (C) ==
Explanation: = is for assignment. == is for comparison (checking equality).

Q13. What will be the output?


int x = 5;
do {
[Link](x + " ");
x--;
} while(x > 3);
Correct Answer: (B) 5 4
Explanation: x=5 prints, x=4 prints, then x becomes 3 and 3>3 is false so loop ends. Output: 5 4

Q14. What is the output of this code?


for(int i = 10; i >= 1; i = i - 3) {
[Link](i + " ");
}
Correct Answer: (A) 10 7 4 1
Explanation: i starts at 10, decreases by 3 each time: 10, 7, 4, 1. Next would be -2, which fails i>=1.

Q15. What keyword is used to define an alternate block when an if condition is FALSE?
Correct Answer: (D) else
Explanation: Java uses else to define the block that runs when the if condition is false.

Q16. What will this program print?


int a = 4, b = 7;
if(a > b) {
[Link](a);
} else {
[Link](b);
}
Correct Answer: (B) 7
Explanation: a = 4 and b = 7. Since 4 > 7 is false, the else block runs and prints b which is 7.

Q17. What is the output of the following code?


for(int i = 1; i <= 10; i++) {
if(i == 6) break;
[Link](i + " ");
}
Correct Answer: (B) 1 2 3 4 5
Explanation: When i==6, break exits the loop immediately. So only 1 through 5 are printed.

Q18. Which of the following is the correct way to write a for loop in Java?
Correct Answer: (B) for(int i = 0; i < 5; i++)
Explanation: A for loop uses semicolons (;) to separate the three parts: initialization, condition, and update.

Q19. What will be the output?


int x = 15;
if(x > 20) {
[Link]("A");
} else if(x > 10) {
[Link]("B");
} else if(x > 5) {
[Link]("C");
} else {
[Link]("D");
}
Correct Answer: (B) B
Explanation: x=15. First condition (x>20) is false. Second condition (x>10) is true, so prints 'B'.

Q20. What is the correct output of this code?


int sum = 0;
for(int i = 1; i <= 4; i++) {
sum = sum + i;
}
[Link](sum);
Correct Answer: (B) 10
Explanation: sum = 0+1+2+3+4 = 10. The loop adds each value of i from 1 to 4.

End of Answer Key | All 20 MCQs Explained | For Teacher Use Only

You might also like