Java Programming Questions
1. What is the output of the following code?
A. Hello, World!
B. Compilation error
C. Runtime error
D. No output
A. Hello, World!
2. Which of the following is not a primitive data type in Java?
A. int
B. float
C. String
D. double
C. String
3. What is the output of the following code?
A. 10
B. 11
C. 12
D. 13
C. 12
4. What is the output of the following code?
A. A
B. B
C. Compilation error
D. Runtime error
A. A
5. What is the output of the following code?
A. 1
B. 2
C. 3
D. 4
C. 3
6. Which keyword is used to inherit a class in Java?
A. extends
B. implements
C. super
D. this
A. extends
7. Which concept allows a method to have multiple forms in Java?
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Abstraction
C. Polymorphism
8. What is the output of the following code?
A. Error
B. No output
C. Compilation error
D. Runtime error
A. Error
9. What is the output of the following code?
A. 4
B. 5
C. 6
D. Compilation error
B. 5
10. What is the output of the following code?
A. Constructor called
B. No output
C. Compilation error
D. Runtime error
A. Constructor called
11. Which class is used to read data from a file in Java?
A. FileReader
B. FileWriter
C. BufferedReader
D. Both a and c
D. Both a and c
12. Which collection stores unique elements in Java?
A. ArrayList
B. HashSet
C. LinkedList
D. HashMap
B. HashSet
13. Which method is used to start a thread in Java?
A. run()
B. start()
C. execute()
D. begin()
B. start()
14. What is the output of the following code?
A. 5
B. 0
C. Compilation error
D. Runtime error
A. 5
15. What is the output of the following code?
A. 5
B. 10
C. Runtime error
D. Compilation error
B. 10
16. What is the output of the following code?
A. 1
B. 5
C. Compilation error
D. Runtime error
B. 5
17. Which annotation is used to override a method in Java?
A. @Override
B. @Deprecated
C. @SuppressWarnings
D. @FunctionalInterface
A. @Override
18. Which class is used to inspect classes at runtime in Java?
A. Class
B. Object
C. Method
D. Field
A. Class
19. Which interface must a class implement to be serializable in Java?
A. Serializable
B. Cloneable
C. Comparable
D. Runnable
A. Serializable
20. Which class is used to create a TCP connection in Java?
A. Socket
B. ServerSocket
C. URL
D. DatagramSocket
A. Socket