Java Intermediate Assessment (30 Questions)
Part A: Multiple Choice Questions (1-20)
1. Which of the following is not a valid Java identifier?
A. _count
B. $value
C. 2ndValue
D. value2
Answer: C
2. What is the default value of a boolean variable in Java (instance variable)?
A. true
B. false
C. 0
D. null
Answer: B
3. Which keyword is used to inherit a class in Java?
A. implements
B. extends
C. inherit
D. instanceOf
Answer: B
4. Which of the following is not a primitive data type?
A. byte
B. short
C. String
D. float
Answer: C
5. Which of the following is true about constructors?
Java Intermediate Assessment (30 Questions)
A. Constructors can return a value.
B. Constructors can be static.
C. Constructors have the same name as the class.
D. Constructors can be private only.
Answer: C
6. What is the result of `10 + 20 + "30"`?
A. 3030
B. 102030
C. 30 + "30"
D. 3030 (as String)
Answer: D
7. What is the output of `System.out.println(5/2);` in Java?
A. 2
B. 2.5
C. 3
D. 2.0
Answer: A
8. What does JVM stand for?
A. Java Variable Method
B. Java Virtual Machine
C. Java Verified Method
D. Java Volatile Memory
Answer: B
9. Which package is automatically imported in every Java program?
A. java.lang
B. java.io
C. java.util
Java Intermediate Assessment (30 Questions)
D. java.net
Answer: A
10. What will happen if the main method is made private?
A. It will run normally
B. Compile-time error
C. Runtime error
D. The program will ignore it
Answer: C
11. Which interface must be implemented to sort elements in a natural order?
A. Comparator
B. Iterable
C. Serializable
D. Comparable
Answer: D
12. Which access modifier allows access within the same package and outside via inheritance?
A. private
B. protected
C. default
D. public
Answer: B
13. What does the `final` keyword do when used with a method?
A. Prevents overriding
B. Prevents calling
C. Makes it static
D. Converts it into an abstract method
Answer: A
Java Intermediate Assessment (30 Questions)
14. Which data type takes the least memory?
A. byte
B. short
C. int
D. char
Answer: A
15. Which of the following is NOT a valid exception type?
A. IOException
B. FileNotFoundException
C. ArithmeticException
D. VirtualMemoryError
Answer: D
16. Which of the following collections implements Map?
A. ArrayList
B. HashSet
C. HashMap
D. TreeList
Answer: C
17. Which loop is guaranteed to run at least once?
A. for
B. while
C. do-while
D. enhanced-for
Answer: C
18. Which method is used to start a thread?
A. run()
B. start()
Java Intermediate Assessment (30 Questions)
C. execute()
D. begin()
Answer: B
19. What is the output of `true && false || true`?
A. true
B. false
C. Compilation error
D. None
Answer: A
20. Which statement is true about garbage collection in Java?
A. It must be manually invoked
B. Objects with no references are eligible
C. JVM never deletes objects
D. finalize() is always called
Answer: B
Part B: Programming Questions (21-30)
21. Predict the output:
public class Test {
public static void main(String[] args) {
int a = 5;
System.out.println(++a * 2);
Answer: 12
22. Complete the program to read a number using BufferedReader:
Java Intermediate Assessment (30 Questions)
import java.io.*;
public class ReadInput {
public static void main(String[] args) throws IOException {
// Complete here
Answer:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number: ");
int num = Integer.parseInt(br.readLine());
System.out.println("You entered: " + num);
23. What will be the output?
class Demo {
static int count = 0;
Demo() {
count++;
public static void main(String[] args) {
new Demo();
new Demo();
System.out.println(count);
Answer: 2
24. Identify the error:
Java Intermediate Assessment (30 Questions)
class A {
private void show() {
System.out.println("A");
class B extends A {
void show() {
System.out.println("B");
Answer: Method hiding occurs. B's `show()` does not override A's method since A's method is private.
25. Complete code to reverse array:
int[] arr = {1, 2, 3, 4, 5};
Answer:
for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
26. Predict the output:
String s1 = "Hello";
String s2 = new String("Hello");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
Answer:
false
Java Intermediate Assessment (30 Questions)
true
27. Fix the syntax error:
public class Sample {
public void main(String[] args) {
System.out.println("Hello");
Answer: main method must be static: `public static void main(String[] args)`
28. Predict the output:
int x = 2;
switch (x) {
case 1:
case 2:
System.out.print("Two ");
case 3:
System.out.print("Three ");
break;
default:
System.out.print("Default ");
Answer: Two Three
29. Check even/odd using ternary:
int num = 7;
Answer:
String result = (num % 2 == 0) ? "Even" : "Odd";
Java Intermediate Assessment (30 Questions)
System.out.println(result);
30. Predict the output:
int[] arr = new int[5];
System.out.println(arr[0]);
Answer: 0