Java Basics
1. Which of these is not a primitive data type in Java?
o a) int
o b) float
o c) boolean
o d) string
Ans: d
2. What is the default value of an int variable in Java?
o a) 0
o b) null
o c) undefined
o d) garbage
Ans: a
3. Java is:
o a) Compiled
o b) Interpreted
o c) Both compiled and interpreted
o d) None
Ans: c
4. The size of a boolean variable is:
o a) 1 byte
o b) 2 bytes
o c) JVM dependent
o d) Not defined
Ans: c
5. Which of these is used to terminate a statement in Java?
o a) .
o b) ,
o c) ;
o d) :
Ans: c
6. Which of the following is not a Java keyword?
o a) static
o b) Boolean
o c) void
o d) private
Ans: b
7. Which of these is a valid identifier in Java?
o a) 1variable
o b) _var
o c) $variable
o d) variable-1
Ans: b
8. What does JVM stand for?
o a) Java Variable Machine
o b) Java Virtual Machine
o c) Java Visual Machine
o d) None
Ans: b
9. Which of these is not a wrapper class?
o a) Integer
o b) Boolean
o c) Character
o d) String
Ans: d
10. Which operator is used for concatenation of strings?
o a) +
o b) &
o c) .
o d) *
Ans: a
Object-Oriented Programming
11. Which of these is not a principle of OOP?
o a) Encapsulation
o b) Inheritance
o c) Compilation
o d) Polymorphism
Ans: c
12. Abstract classes in Java:
o a) Cannot have any methods
o b) Cannot be instantiated
o c) Must be final
o d) None
Ans: b
13. A constructor:
o a) Must have the same name as the class
o b) Must have return type
o c) Must be static
o d) None
Ans: a
14. Method overloading is an example of:
o a) Runtime polymorphism
o b) Compile-time polymorphism
o c) Inheritance
o d) Abstraction
Ans: b
15. Which of these allows multiple inheritance in Java?
o a) Classes
o b) Interfaces
o c) Abstract classes
o d) Packages
Ans: b
16. An interface can contain:
o a) Abstract methods only
o b) Concrete methods only
o c) Both
o d) Variables and methods
Ans: a
17. Which keyword is used to prevent inheritance?
o a) abstract
o b) static
o c) final
o d) private
Ans: c
18. Which of the following is true about constructors?
o a) They can be overloaded
o b) They cannot be overridden
o c) They are called automatically
o d) All of the above
Ans: d
19. Which of the following is NOT a type of inheritance in Java?
o a) Single
o b) Multiple
o c) Multilevel
o d) Hierarchical
Ans: b
20. Which method is called when an object is garbage collected?
o a) finalize()
o b) destroy()
o c) terminate()
o d) delete()
Ans: a
Exceptions & Packages
21. What is the superclass of all exceptions?
o a) Throwable
o b) Exception
o c) RuntimeException
o d) Error
Ans: a
22. Checked exceptions are:
o a) Not checked at compile time
o b) Checked at compile time
o c) Run-time exceptions
o d) Errors
Ans: b
23. Which block always executes?
o a) try
o b) catch
o c) finally
o d) throw
Ans: c
24. Which of these is a checked exception?
o a) NullPointerException
o b) ArithmeticException
o c) IOException
o d) ArrayIndexOutOfBoundsException
Ans: c
25. Which of the following is not a package?
o a) java.lang
o b) java.util
o c) java.io
o d) java.system
Ans: d
Collections
26. Which of the following is ordered and allows duplicates?
o a) Set
o b) Map
o c) List
o d) None
Ans: c
27. Which of the following is thread-safe?
o a) HashMap
o b) Hashtable
o c) ArrayList
o d) LinkedList
Ans: b
28. Which method removes all elements of a collection?
o a) remove()
o b) delete()
o c) clear()
o d) removeAll()
Ans: c
29. What does the Map interface map?
o a) Keys to values
o b) Objects to objects
o c) Values to keys
o d) None
Ans: a
30. Which of the following allows null keys?
o a) Hashtable
o b) HashMap
o c) TreeMap
o d) None
Ans: b
Multithreading
31. Which method is used to start a thread?
o a) run()
o b) start()
o c) execute()
o d) init()
Ans: b
32. Which interface is implemented for creating threads?
o a) Runnable
o b) Threadable
o c) Executable
o d) None
Ans: a
33. Which method is used to pause a thread?
o a) stop()
o b) sleep()
o c) suspend()
o d) wait()
Ans: b
34. Which is not a thread state?
o a) Running
o b) Waiting
o c) Sleeping
o d) Terminated
Ans: c
35. Synchronization is used to:
o a) Increase speed
o b) Control access to shared resources
o c) Create threads
o d) None
Ans: b
Miscellaneous
36. What is the default value of a reference variable?
o a) 0
o b) null
o c) false
o d) undefined
Ans: b
37. The output of System.out.println(10 + 20 + "30") is:
o a) 3030
o b) 102030
o c) 3030
o d) 3030
Ans: c
38. Which of these is a marker interface?
o a) Runnable
o b) Cloneable
o c) Comparable
o d) Serializable
Ans: b
39. What is the size of int in Java?
o a) 8 bits
o b) 16 bits
o c) 32 bits
o d) 64 bits
Ans: c
40. Which method is used to compare two strings ignoring case?
o a) equals()
o b) compareTo()
o c) equalsIgnoreCase()
o d) ==
Ans: c
More Practice (41–100)
41. Java was developed by?
o a) Bjarne Stroustrup
o b) James Gosling
o c) Dennis Ritchie
o d) Guido van Rossum
Ans: b
42. Which memory stores method calls and local variables?
o a) Heap
o b) Stack
o c) Method area
o d) Register
Ans: b
43. Which memory stores objects?
o a) Heap
o b) Stack
o c) Method area
o d) Register
Ans: a
44. Which keyword is used to inherit a class?
o a) inherit
o b) extends
o c) implements
o d) super
Ans: b
45. Which operator is used to compare values?
o a) =
o b) ==
o c) !=
o d) =>
Ans: b
46. Which class is the parent of all classes?
o a) Class
o b) Object
o c) Super
o d) Main
Ans: b
47. Which exception occurs when array index is out of bounds?
o a) IndexOutOfBoundsException
o b) ArrayIndexOutOfBoundsException
o c) NullPointerException
o d) None
Ans: b
48. Which keyword is used to create an object?
o a) create
o b) new
o c) object
o d) init
Ans: b
49. Which keyword refers to the current object?
o a) this
o b) super
o c) self
o d) obj
Ans: a
More Practice MCQs (51–100)
51. Which method is used to find the length of a string?
• a) length()
• b) size()
• c) getSize()
• d) count()
Ans: a
52. Which keyword is used to call the parent class constructor?
• a) this
• b) super
• c) parent
• d) base
Ans: b
53. Which of these can be declared final?
• a) Variable
• b) Method
• c) Class
• d) All of the above
Ans: d
54. Which class do all exceptions inherit from?
• a) Exception
• b) Error
• c) Throwable
• d) RuntimeException
Ans: c
55. Which of the following can implement multiple interfaces?
• a) Class
• b) Interface
• c) Both
• d) None
Ans: a
56. Which method is used to stop a thread permanently?
• a) stop()
• b) suspend()
• c) wait()
• d) kill()
Ans: a
57. Which is true about static methods?
• a) They can access instance variables
• b) They can access only static variables
• c) They can access both static and instance
• d) None
Ans: b
58. Which keyword is used to create a constant variable?
• a) const
• b) constant
• c) final
• d) immutable
Ans: c
59. Which of the following cannot be instantiated?
• a) Abstract class
• b) Interface
• c) Both
• d) None
Ans: c
60. What happens if the main() method is not declared as static?
• a) Compilation error
• b) Runtime error
• c) Executes normally
• d) None
Ans: b
Operators & Expressions
61. What is the output of System.out.println(10/3);?
• a) 3.33
• b) 3
• c) 3.0
• d) Error
Ans: b
62. Which operator is used to test equality?
• a) =
• b) ==
• c) ===
• d) equals()
Ans: b
63. Which of the following is a logical operator?
• a) &
• b) &&
• c) |
• d) All
Ans: d
64. What is the result of true && false?
• a) true
• b) false
• c) 1
• d) 0
Ans: b
65. Which operator is used to increment by 1?
• a) ++
• b) +=1
• c) Both
• d) None
Ans: c
Input/Output & Files
66. Which package contains Scanner class?
• a) java.io
• b) java.lang
• c) java.util
• d) java.input
Ans: c
67. Which stream is used for binary input?
• a) Reader
• b) InputStream
• c) Scanner
• d) None
Ans: b
68. What does read() method of InputStream return?
• a) int
• b) char
• c) byte
• d) String
Ans: a
69. Which class is used to write to a file?
• a) FileReader
• b) FileWriter
• c) FileScanner
• d) FileInputStream
Ans: b
70. Which method closes a file stream?
• a) terminate()
• b) stop()
• c) close()
• d) end()
Ans: c
Threads & Synchronization
71. Which of these is NOT a valid thread state?
• a) Runnable
• b) Waiting
• c) Running
• d) Scheduling
Ans: d
72. Threads can communicate with each other using:
• a) wait()
• b) notify()
• c) notifyAll()
• d) All
Ans: d
73. Which method releases the lock on an object?
• a) wait()
• b) sleep()
• c) join()
• d) yield()
Ans: a
74. Which method is used to check if a thread is alive?
• a) alive()
• b) isAlive()
• c) status()
• d) getState()
Ans: b
75. Which keyword is used to synchronize a method?
• a) sync
• b) synchronized
• c) static
• d) final
Ans: b
Advanced Topics
76. Which of these is used to create a custom exception?
• a) extend Error
• b) extend Exception
• c) implement Throwable
• d) None
Ans: b
77. Which of these is NOT part of the Java Collection Framework?
• a) HashSet
• b) ArrayList
• c) Vector
• d) Arrays
Ans: d
78. Which method is used to sort a list?
• a) sort()
• b) Collections.sort()
• c) Arrays.sort()
• d) Both b and c
Ans: d
79. Which of these classes is synchronized?
• a) ArrayList
• b) Vector
• c) HashMap
• d) LinkedList
Ans: b
80. Which data structure is LIFO?
• a) Queue
• b) Stack
• c) LinkedList
• d) Tree
Ans: b
Miscellaneous & Theory
81. Java is platform independent because of:
• a) Bytecode
• b) Compiler
• c) Interpreter
• d) JVM
Ans: a
82. Java is:
• a) Procedural
• b) Functional
• c) Object-oriented
• d) All
Ans: c
83. Which of these is used to exit a loop?
• a) break
• b) continue
• c) return
• d) exit
Ans: a
84. Which of these skips to next iteration of loop?
• a) break
• b) continue
• c) return
• d) exit
Ans: b
85. Which of these is not a valid access modifier?
• a) public
• b) private
• c) protected
• d) friendly
Ans: d
86. Which keyword is used to define a package?
• a) package
• b) import
• c) include
• d) namespace
Ans: a
87. Which keyword is used to import a class?
• a) package
• b) import
• c) include
• d) using
Ans: b
88. What is the default package in Java?
• a) java
• b) java.lang
• c) java.util
• d) No default package
Ans: b
89. What is the default value of a boolean variable?
• a) true
• b) false
• c) 0
• d) null
Ans: b
90. Which keyword is used for inheritance?
• a) extends
• b) implements
• c) super
• d) this
Ans: a
Practice Output & Debug
91. What is the output of:
java
CopyEdit
System.out.println(“Hello” + 1 + 2);
• a) Hello3
• b) 3Hello
• c) Hello12
• d) Error
Ans: c
92. What is the output of:
java
CopyEdit
System.out.println(1 + 2 + “Hello”);
• a) 3Hello
• b) Hello3
• c) Hello12
• d) Error
Ans: a
93. What is the output of:
java
CopyEdit
int x = 10;
System.out.println(++x);
• a) 10
• b) 11
• c) 9
• d) Error
Ans: b
94. Which of these is not an assignment operator?
• a) =
• b) +=
• c) ==
• d) %=
Ans: c
95. Which of these is not a primitive type?
• a) byte
• b) int
• c) float
• d) String
Ans: d
96. Which of these can be overloaded?
• a) Constructor
• b) Method
• c) Operator
• d) Both a and b
Ans: d
97. Which of these cannot be overridden?
• a) static method
• b) final method
• c) private method
• d) All of the above
Ans: d
98. What is the size of a char in Java?
• a) 1 byte
• b) 2 bytes
• c) 4 bytes
• d) JVM dependent
Ans: b
99. What does JDK stand for?
• a) Java Development Kit
• b) Java Debug Kit
• c) Java Deployment Kit
• d) Java Design Kit
Ans: a
100. Which of the following is used to document Java code?
• a) /* */
• b) //
• c) /** */
• d) #
Ans: c