# Java Interview Questions (Topic-wise)
## 1. Classes and Objects
- What is a class in Java?
- What is an object? How is it created?
- Difference between a class and an object.
- Can we have multiple objects of the same class?
- What is an anonymous object in Java? Give an example.
- Explain the lifecycle of an object.
## 2. Constructors
- What is a constructor?
- Types of constructors in Java.
- Difference between constructor and method.
- Can a constructor be private? Why/when is it used?
- Can constructors be overloaded?
- Can a constructor return a value? Why not?
- What happens if we don’t define a constructor?
## 3. Keywords
- What are reserved keywords in Java?
- Explain the use of `this` keyword.
- Explain the use of `super` keyword.
- Difference between `final`, `finally`, and `finalize`.
- Purpose of `static` keyword.
- Difference between `throw` and `throws`.
- Explain `transient`, `volatile`, and `synchronized`.
## 4. Packages
- What is a package in Java? Why do we use it?
- Difference between built-in and user-defined packages.
- How to import a package in Java?
- Can we access classes of one package into another? How?
- Difference between `import package.*` and `import package.classname`.
## 5. Static
- What does the `static` keyword mean?
- Difference between static variable, static method, and static block.
- Why can’t we access non-static variables inside static methods?
- What is a static nested class?
- Can a constructor be static? Why not?
## 6. Singleton Classes
- What is a Singleton class?
- How do you implement a Singleton in Java?
- Difference between eager initialization and lazy initialization in Singleton.
- Can a Singleton be broken using reflection? How do you prevent it?
- Can a Singleton class be cloned?
## 7. Inbuilt Methods
- Name some commonly used inbuilt methods in Java.
- Difference between `equals()` and `==`.
- Difference between `hashCode()` and `toString()`.
- Explain the `compareTo()` method.
- What is the use of `getClass()` method?
## 8. Inheritance
- What is inheritance? Why is it used?
- Types of inheritance in Java. Which are supported/not supported?
- What is the difference between `extends` and `implements`?
- Explain method overriding with an example.
- Can constructors be inherited?
- What is the diamond problem in inheritance?
## 9. Polymorphism
- What is polymorphism?
- Difference between compile-time and runtime polymorphism.
- What is method overloading?
- What is method overriding?
- Can we override static methods? Why/why not?
- Can we overload the `main` method in Java?
## 10. Abstraction
- What is abstraction? Why is it used?
- Difference between abstract class and interface.
- Can we create an object of an abstract class?
- Can abstract classes have constructors?
- Can an abstract class have concrete methods?
## 11. Encapsulation
- What is encapsulation?
- How does encapsulation improve security?
- Difference between encapsulation and abstraction.
- Example of encapsulation in real-world Java.
## 12. Access Control
- What are access modifiers in Java?
- Difference between public, private, protected, and default.
- Can we make a constructor private? Why?
- What happens if no access modifier is specified?
## 13. Inbuilt Packages
- List some commonly used inbuilt packages in Java.
- What is `java.util` used for?
- What is `java.lang` package?
- What is `java.io` package?
## 14. Abstract Classes
- What is an abstract class?
- Can abstract classes have constructors?
- Difference between abstract class and concrete class.
- Can an abstract class have `final` methods?
## 15. Interfaces
- What is an interface in Java?
- Difference between interface and abstract class.
- Can an interface have constructors?
- What is a marker interface? Give examples.
- What is a functional interface?
- Can interfaces have default methods?
## 16. Annotations
- What are annotations in Java?
- Difference between annotations and comments.
- Explain `@Override`, `@Deprecated`, and `@SuppressWarnings`.
- What is a custom annotation?
## 17. Generics
- What are generics in Java?
- Advantages of using generics.
- Difference between `List` and `List`.
- What is type erasure in generics?
- Can generics be used with primitive types?
## 18. Custom ArrayList
- How do you implement your own ArrayList in Java?
- How does `ArrayList` internally work?
- Difference between Array and ArrayList.
- How does resizing happen in an ArrayList?
## 19. Lambda Expressions
- What is a lambda expression?
- Advantages of using lambda expressions.
- Syntax of lambda in Java.
- Difference between lambda expression and anonymous class.
- Can lambda expressions capture variables?
## 20. Exception Handling
- What is exception handling?
- Difference between checked and unchecked exceptions.
- What is the difference between `throw` and `throws`?
- Explain try-catch-finally with an example.
- Can a `finally` block be skipped?
- What is the difference between `Exception` and `Error`?
## 21. Object Cloning
- What is object cloning in Java?
- Difference between shallow copy and deep copy.
- How do you implement cloning?
- What are the drawbacks of cloning in Java?
- Difference between copy constructor and clone method.