Java_Interview_Questions
Java_Interview_Questions
Answer: JDK (Java Development Kit) includes tools to develop Java programs, JRE (Java Runtime
Environment) includes JVM + libraries to run Java programs, and JVM (Java Virtual Machine) executes Java
bytecode.
Answer: A constructor is a special method called when an object is instantiated. It initializes the object.
Answer: Static methods belong to the class and don't require an object; non-static methods require an object
to be called.
Answer: Defining multiple methods with the same name but different parameters within the same class.
Answer: They define visibility: public, private, protected, and default (no modifier).
Answer: String is immutable, StringBuilder is mutable and not thread-safe, StringBuffer is mutable and
thread-safe.
Answer: final variable = constant, final method = can't be overridden, final class = can't be inherited.
Answer: List: ordered and allows duplicates, Set: unordered and no duplicates, Map: key-value pairs.
Answer: ArrayList: fast access, slow insert/delete; LinkedList: slow access, fast insert/delete.
Answer: A map-based collection that stores key-value pairs. Keys are unique.
Answer: A class that cannot be instantiated and can have both abstract and concrete methods.
Answer: One function behaves differently based on input - method overloading and overriding.
Answer: Wrapping variables and methods together in a class and restricting direct access.
Answer: 'throw' is used to throw an exception, 'throws' declares exceptions a method can throw.
Answer: null.
Answer: public: everywhere, private: within class, protected: package + subclass, default: package only.
Answer: No. Java does not support multiple inheritance using classes.