Core Java Quiz ( Intermediate ) - All Questions
This intermediate Core Java quiz is designed for developers who understand Java basics and want to strengthen applied concepts. It covers OOP principles, memory management, strings, collections, exception handling, multithreading basics, and commonly asked Java interview questions.
Question 1: What is the main difference between JDK and JRE?
- JDK runs programs, JRE compiles them
- JDK contains development tools, JRE only runs programs
- JRE is larger than JDK
- They are the same
Explanation: JDK includes compiler and tools, while JRE only runs Java programs.
Question 2: What is the purpose of the JVM?
- Write Java code
- Compile Java code
- Execute bytecode on any platform
- Manage databases
Explanation: JVM executes bytecode and enables platform independence.
Question 3: Why is Java called platform-independent?
- It runs only on Windows
- It uses C language internally
- Bytecode runs on JVM across platforms
- It does not need OS
Explanation: Java bytecode runs on JVM regardless of OS.
Question 4: What is constructor used for?
- Destroy objects
- Initialize objects
- Call methods
- Free memory
Explanation: Constructors initialize objects.
Question 5: Which rule applies to constructors?
- Must have return type
- Can be static
- Name must match class name
- Can be inherited
Explanation: Constructor name must match class name.
Question 6: What is constructor overloading?
- Multiple constructors with same parameters
- Multiple constructors with different parameters
- Calling parent constructor
- Overriding constructors
Explanation: Overloading uses different parameter lists.
Question 7: What happens if no constructor is defined?
- Compilation error
- Runtime error
- Default constructor is created
- Object cannot be created
Explanation: Java provides a default constructor.
Question 8: What is the default value of instance variables?
- Garbage value
- Null or zero values
- Must be initialized
- Depends on OS
Explanation: Instance variables get default values.
Question 9: What is method overloading resolved at?
- Runtime
- Compile time
- JVM startup
- Execution time
Explanation: Method overloading is compile-time polymorphism.
Question 10: What is method overriding resolved at?
- Compile time
- Runtime
- Link time
- Load time
Explanation: Method overriding is runtime polymorphism.
Question 11: Which keyword prevents method overriding?
- static
- private
- final
- abstract
Explanation: final methods cannot be overridden.
Question 12: Why can't static methods be overridden?
- They belong to object
- They belong to class
- They are abstract
- They are final
Explanation: Static methods belong to the class.
Question 13: What is upcasting?
- Parent to child reference
- Child to parent reference
- Object destruction
- Type conversion
Explanation: Upcasting assigns child object to parent reference.
Question 14: What is downcasting?
- Parent to child reference
- Child to parent reference
- Implicit casting
- Compile-time casting
Explanation: Downcasting converts parent reference to child.
Question 15: Which keyword checks object type before casting?
- this
- super
- instanceof
- typeof
Explanation: instanceof checks object type.
Question 16: What is abstraction?
- Hiding data
- Showing only essential features
- Code reuse
- Multiple inheritance
Explanation: Abstraction shows essential behavior.
Question 17: Which supports multiple inheritance in Java?
- Classes
- Abstract classes
- Interfaces
- Objects
Explanation: Interfaces support multiple inheritance.
Question 18: What is encapsulation?
- Code reuse
- Binding data and methods
- Method hiding
- Inheritance
Explanation: Encapsulation binds data with methods.
Question 19: Why are variables made private?
- Performance
- Security and control
- Compilation speed
- Memory usage
Explanation: Private variables protect data.
Question 20: Which keyword is used to access private data?
- this
- super
- get/set methods
- static
Explanation: Getters and setters access private data.
Question 21: What is String immutability?
- Strings cannot be modified
- Strings are thread-safe
- Strings are faster
- Strings are stored in heap only
Explanation: String values cannot be changed once created.
Question 22: Why are Strings immutable?
- Security and memory optimization
- Performance only
- Garbage collection
- Compilation speed
Explanation: Immutability improves security and memory reuse.
Question 23: What is String Pool?
- Heap memory
- Special memory for strings
- Stack memory
- Cache memory
Explanation: String Pool stores string literals.
Question 24: Which class allows mutable strings?
- String
- StringBuffer
- StringBuilder
- Both B and C
Explanation: StringBuffer and StringBuilder are mutable.
Question 25: Difference between StringBuffer and StringBuilder?
- Performance
- Thread safety
- Memory
- Syntax
Explanation: StringBuffer is thread-safe, StringBuilder is not.
Question 26: What is the root interface of Collections framework?
- List
- Set
- Collection
- Iterable
Explanation: Collection is the root interface.
Question 27: Which collection allows duplicate values?
Explanation: List allows duplicate elements.
Question 28: Which collection maintains insertion order?
- HashSet
- TreeSet
- LinkedHashSet
- Set
Explanation: LinkedHashSet maintains insertion order.
Question 29: Which collection is synchronized?
- ArrayList
- LinkedList
- Vector
- HashSet
Explanation: Vector is synchronized.
Question 30: What is Iterator used for?
- Sorting
- Traversing collections
- Indexing
- Searching
Explanation: Iterator is used to traverse collections.
Question 31: Which exception occurs at runtime?
- IOException
- SQLException
- RuntimeException
- ClassNotFoundException
Explanation: RuntimeException occurs during execution.
Question 32: Which exceptions must be handled explicitly?
- Runtime
- Unchecked
- Checked
- All
Explanation: Checked exceptions must be handled.
Question 33: What is finally block used for?
- Exception creation
- Cleanup code
- Handling errors
- Stopping execution
Explanation: finally executes cleanup code.
Question 34: What is multithreading?
- Multiple programs
- Multiple processes
- Multiple threads executing concurrently
- Parallel JVMs
Explanation: Multithreading runs multiple threads.
Question 35: Which interface is used to create a thread?
- Thread
- Runnable
- Callable
- Executor
Explanation: Runnable is commonly used to create threads.
Question 36: Which method starts a thread?
- run()
- execute()
- start()
- init()
Explanation: start() begins thread execution.
Question 37: What happens if run() is called directly?
- New thread starts
- Thread stops
- Method executes in current thread
- Compilation error
Explanation: run() executes like a normal method.
Question 38: Which keyword ensures thread safety?
- volatile
- static
- final
- synchronized
Explanation: synchronized controls concurrent access.
Question 39: What is deadlock?
- Thread termination
- Threads waiting indefinitely for resources
- Fast execution
- Memory leak
Explanation: Deadlock is circular waiting.
Question 40: Which memory area stores objects?
- Stack
- Heap
- Method area
- Register
Explanation: Objects are stored in heap memory.
Question 41: Which memory area stores local variables?
- Heap
- Stack
- Method area
- Class loader
Explanation: Local variables are stored in stack.
Question 42: What is garbage collection?
- Manual memory cleanup
- Automatic memory management
- Thread management
- File cleanup
Explanation: GC automatically frees unused memory.
Question 43: Which method suggests garbage collection?
- finalize()
- gc()
- System.gc()
- collect()
Explanation: System.gc() requests garbage collection.
Question 44: Which keyword is used to create immutable objects?
Explanation: final helps create immutability.
Question 45: Which Java feature improves code reusability?
- Encapsulation
- Inheritance
- Abstraction
- Compilation
Explanation: Inheritance enables reuse.
Question 46: What is the main purpose of Core Java?
- Framework development
- Strong foundation for Java applications
- UI creation
- Database management
Explanation: Core Java builds a strong programming base.