☕
Q1. What are the main features of Java?
A. Object-oriented, platform-independent (bytecode + JVM), robust (GC), secure (sandboxing, strong typing), multithreaded, rich standard library, and great tooling/ecosystem.
Entry
☕
Q2. What is the difference between JDK, JRE, and JVM?
A. JVM runs bytecode. JRE = JVM + standard libraries to run apps. JDK = JRE + compiler and dev tools to build apps.
Entry
☕
Q3. What are the four pillars of OOP?
A. Encapsulation, inheritance, polymorphism, and abstraction.
Entry
☕
Q4. What is a class vs object?
A. A class is a blueprint; an object is an instance created from a class.
Entry
☕
Q5. What is the parent class of all classes in Java?
A. java.lang.Object.
Entry
☕
Q6. Do interfaces extend java.lang.Object?
A. No. Interfaces do not extend Object, but any class that implements an interface still extends Object.
Entry
☕
Q7. What is inheritance in Java?
A. A subclass reuses and extends behavior/state of a superclass using extends.
Entry
☕
Q8. Does Java support multiple inheritance of classes?
A. No. A class cannot extend multiple classes. Use interfaces to achieve “multiple inheritance of type”.
Entry
☕
Q9. How can Java implement multiple inheritance?
A. A class can implement multiple interfaces: class C implements A, B.
Entry
☕
Q10. What is method overloading?
A. Same method name with different parameters (compile-time).
Entry
☕
Q11. What is method overriding?
A. A subclass provides a new implementation with the same signature (runtime polymorphism).
Entry
☕
Q12. What is compile-time vs runtime polymorphism?
A. Overloading is resolved at compile-time; overriding is resolved at runtime using dynamic dispatch.
Entry
☕
Q13. What is the JVM?
A. Java Virtual Machine runs bytecode and provides GC, JIT compilation, and runtime services.
Entry
☕
Q14. What is platform independence in Java?
A. Java compiles to bytecode. Any platform with a compatible JVM can run the same bytecode.
Entry
☕
Q15. What is the latest version of Java?
A. Java releases frequently (roughly every 6 months). For production, many teams choose the latest LTS release and verify the current versions from Oracle/Adoptium release pages.
Entry
☕
Q16. == vs equals()?
A. == compares references (identity). equals() compares logical equality (if implemented).
Entry
☕
Q17. Why are Strings immutable in Java?
A. Immutability improves security, caching (string pool), thread-safety, and makes hashing stable for maps/sets.
Entry
☕
Q18. String vs StringBuilder vs StringBuffer?
A. String is immutable. StringBuilder is mutable and fast (not thread-safe). StringBuffer is mutable and synchronized (thread-safe but slower).
Entry
☕
Q19. What is an exception?
A. An error event that disrupts normal flow; handled with try/catch/finally.
Entry
☕
Q20. Checked vs unchecked exceptions?
A. Checked exceptions must be caught/declared; unchecked exceptions (RuntimeException) do not have to be declared.
Entry
☕
Q21. final vs finally vs finalize?
A. final: constant/non-overridable. finally: block after try/catch. finalize(): legacy GC hook; avoid in modern Java.
Entry
☕
Q22. What is an interface?
A. A contract of members a class implements. Interfaces can have default/static methods (Java 8+).
Entry
☕
Q23. abstract class vs interface?
A. Abstract class can hold state and constructors; interface defines a contract (plus default/static methods). A class can implement multiple interfaces but extend only one class.
Entry
☕
Q24. What is the difference between this() and super()?
A. this() calls another constructor in the same class; super() calls a superclass constructor. Both must be the first statement in a constructor.
Entry
☕
Q25. Are constructors inherited?
A. No. Constructors are not inherited, but superclass constructors run during subclass object creation.
Entry
☕
Q26. What is constructor chaining?
A. Calling one constructor from another using this() or calling the parent constructor using super().
Entry
☕
Q27. Can you create an object without using new?
A. Yes. Examples: reflection (Class.newInstance / Constructor.newInstance), cloning, deserialization, and factory methods.
Entry
☕
Q28. What are access modifiers in Java?
A. private (class only), default/package-private (package), protected (package + subclasses), public (everywhere).
Entry
☕
Q29. What are common non-access modifiers?
A. static, final, abstract, synchronized, transient, volatile, native, strictfp.
Entry
☕
Q30. Can we overload main() method?
A. Yes, but the JVM entry point must be public static void main(String[] args).
Entry
☕
Q31. Why must main() be public and static?
A. public so JVM can access it; static so JVM can invoke it without creating an instance.
Entry
☕
Q32. What is type casting?
A. Converting a value/reference from one type to another. Primitive casting changes numeric type; reference casting changes the declared reference type.
Entry
☕
Q33. What is auto-boxing and unboxing?
A. Auto-boxing wraps primitives into wrapper objects; unboxing extracts primitive values from wrappers.
Entry