TECHNICAL TEST - JAVA
1. Which of the following is not a Java keyword?
A. static
B. Boolean
C. void
D. switch
2. What is the default value of a boolean variable in Java (class-level)?
A. true
B. false
C. null
D. 0
3. Which of the following is used to allocate memory dynamically?
A. malloc()
B. new
C. alloc()
D. create()
4. Which of these is not a primitive data type in Java?
A. int
B. String
C. boolean
D. double
5. Java is platform independent because:
A. It compiles directly to machine code
B. It uses JVM (Java Virtual Machine)
C. It is open source
D. It uses C for compilation
6. Which operator is used for string concatenation in Java?
A. +
B. &
C. .
D. concat
7. Which package is imported by default in every Java program?
A. java.util
B. java.lang
C. java.io
D. java.net
8. What will be the output of:
int x = 5;
System.out.println(x++ + ++x);
A. 11
B. 12
C. 10
D. 13
9. Which of the following can be used to handle exceptions?
A. try-catch
B. throw
C. throws
D. All of the above
10. Which method is the entry point of a Java program?
A. main()
B. start()
C. run()
D. execute()
11. What will be the output of the following code?
String s1 = "abc";
String s2 = new String("abc");
System.out.println(s1 == s2);
A. true
B. false
C. Compiler error
D. Runtime exception
12. Which collection class does not allow duplicates and maintains insertion order?
A. HashSet
B. LinkedHashSet
C. TreeSet
D. PriorityQueue
13. Which statement is true about interfaces in Java?
A. Interfaces can have constructors.
B. Interfaces can have abstract methods and static methods.
C. Interfaces can be instantiated.
D. Interfaces cannot have fields.
14. Which modifier makes a variable accessible only within its own class?
A. protected
B. private
C. public
D. default
15. What will happen if you call Thread.start() twice on the same Thread object?
A. The thread restarts
B. Nothing happens
C. IllegalThreadStateException
D. Thread runs twice
16. Identify the correct statement:
A. A static method can access instance variables directly.
B. A non-static method can access static variables.
C. A static method cannot be overloaded.
D. A class must have a main method to compile.
17. Which Java feature enables method calls to resolve at runtime?
A. Inheritance
B. Polymorphism (Dynamic Binding)
C. Encapsulation
D. Abstraction
18. Which of the following code will create an immutable class?
A. Class with all public fields
B. Class with private fields and no setters
C. Class with private fields and public setters
D. Class with default-access fields
19. What will be the output?
int a = 10;
int b = 20;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + " " + b);
A. 10 20
B. 20 10
C. 30 10
D. 30 20
20. What is the size of an int in Java?
A. 16 bits
B. 32 bits
C. 64 bits
D. Platform dependent
21. Which access modifier allows visibility only within the same package?
A. private
B. protected
C. default (no modifier)
D. public
22. Which keyword is used to prevent a class from being subclassed?
A. static
B. final
C. abstract
D. constant
23. What does the this keyword refer to?
A. Current class object
B. Parent class object
C. Random object in heap
D. Static reference
24. Which exception is unchecked in Java?
A. IOException
B. SQLException
C. ArithmeticException
D. ClassNotFoundException
25. Which statement about Java’s ArrayList is true?
A. It is synchronized.
B. It maintains insertion order.
C. It uses a hash table internally.
D. It cannot store null values.
26. Which of the following statements is true about Java memory management?
A. Java uses explicit deallocation.
B. Garbage collector automatically reclaims memory.
C. You must manually free memory like in C.
D. Java has no memory management.
27. What will be the output?
String str = "Hello";
str.concat(" World");
System.out.println(str);
A. Hello
B. Hello World
C. World
D. null
28. Consider this code:
int x = 0;
while (x++ < 3) {
System.out.print(x);
}
What will be the output?
A. 012
B. 123
C. 0123
D. 1234
29. What is the result of running the following code?
class Test {
static {
System.out.println("Static block");
}
public static void main(String[] args) {
System.out.println("Main method");
}
}
A. Main method
B. Static block
C. Static block followed by Main method
D. Compilation error
30. What is the output?
try {
int data = 10 / 0;
} catch (ArithmeticException e) {
System.out.print("AE ");
} finally {
System.out.print("F");
}
A. AE
B. F
C. AE F
D. Compilation error