🖥️ CSCI 2010 – Mock Midterm Exam
(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();
, 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)
(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();
, 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)