(MCQs) with Answers key
Section A: Java Basics & Output
1. If you compile a Java source file containing a class called MyApp, what is the name of the
resulting file?
A. MyApp.java
B. MyApp.class
C. MyApp.txt
D. MyApp.exe
2. Given the code:
String greeting = "Hello there!";
System.out.println(greeting.length());
What is displayed?
A. 11
B. 12
C. 13
D. 14
3. Which object is used to display normal output to the screen?
A. Scanner
B. System.out
C. Console
D. PrintStream
4. Which statement reads an integer from the keyboard?
A. number = keyboard.readInt();
B. number = keyboard.nextInt();
C. number = System.in.readInt();
D. number = Scanner.next();
Page 1 of 43 3/21/2026, 6:54:41 PM
, 5. Which keyword is NOT required when declaring a named constant?
A. final
B. void
C. public
D. static
6. The Java compiler translates source code into:
A. Machine code
B. Assembly code
C. Bytecode
D. Object code
7. Which is used to display formatted output?
A. System.out.print()
B. System.out.println()
C. System.out.printf()
D. print.format()
Section B: Classes & Objects
8. What is the relationship between a class and an object?
A. A class is a blueprint for creating objects
B. An object is a blueprint for creating classes
C. Classes and objects are equivalent
D. Objects cannot exist without classes
9. Which of the following does NOT increase the value of number by 1?
A. number += 1
B. number + 1
C. number = number + 1
D. number++
10. Correct way to test if two strings s1 and s2 are exactly the same:
A. s1 == s2
B. s1.equals(s2)
C. s1.compareTo(s2)
D. s1.equalsIgnoreCase(s2)
Page 2 of 43 3/21/2026, 6:54:41 PM
, 11. Difference between a while loop and a do-while loop:
A. while evaluates after the loop; do-while before
B. while evaluates before the loop; do-while after
C. while runs once; do-while may not run
D. No difference
12. Why is using a DEBUG flag helpful when tracing variables?
A. It allows variables to be hidden
B. It turns tracing messages on and off easily
C. It speeds up compilation
D. It prevents runtime errors
13. What is displayed by the code:
for (int i = 1; i <= 5; i++)
if (i == 4)
break;
System.out.println("boing");
A. boing boing boing boing
B. boing boing boing
C. boing boing
D. boing
14. Which Java type is used for true/false values?
A. Boolean
B. boolean
C. int
D. String
15. Correct way to call the exit method in Java:
A. exit(0);
B. System.exit(0);
C. System.terminate();
D. exitProgram();
16. Correct way to declare an enumeration:
A. enum Suits { HEARTS, SPADES, DIAMONDS, CLUBS }
B. enum Suits = [HEARTS, SPADES, DIAMONDS, CLUBS];
Page 3 of 43 3/21/2026, 6:54:41 PM
, C. enum Suits();
D. enum Suits { "HEARTS", "SPADES", "DIAMONDS", "CLUBS" };
Section C: Loops & Methods
17. Equivalent while loop for:
for (count = 0; count < 4; count++)
System.out.println(count);
A. count = 0; while (count < 4) { count++; }
B. count = 0; while (count < 4) { System.out.println(count); count++; }
C. count = 1; while (count < 4) { System.out.println(count); }
D. count = 0; while (count <= 4) { System.out.println(count); count++; }
18. How does a while loop work?
A. Repeats the body until the controlling expression is false
B. Repeats once then stops
C. Executes only if the expression is true
D. Loops infinitely by default
19. A method is:
A. A variable in a class
B. A member of a class that defines an operation on an object
C. A type of constructor
D. A static class
20. Calling a method within the same class using methodName() is equivalent to:
A. this.methodName()
B. super.methodName()
C. ClassName.methodName()
D. methodName(); (no difference)
21. Difference between public and private instance variables:
A. Public accessible only inside the class
B. Private accessible outside the class
C. Public accessible outside; private accessible only inside
D. No difference
Page 4 of 43 3/21/2026, 6:54:41 PM