What is the difference between a class and an object?
A class is a blueprint, while an object is an instance created from that blueprint
What is the difference between primitive and reference types in Java?
Primitives store actual values (e.g., int, double), while references store memory addresses pointing to objects
What is an abstract class
A class that cannot be instantiated and may contain both abstract and concrete methods
What is an interface in Java?
A contract that specifies methods a class must implement; cannot contain state (except constants)
Can a class extend multiple abstract classes? Can it implement multiple interfaces
No, only single inheritance for classes. Yes, multiple interface implementation is allowed
Define subtype polymorphism.
The ability to treat an object of a subclass as if it were of its superclass or interface type
Difference between subclass and subtype?
Subclass is a syntactic relationship (extends). Subtype is a semantic relationship: it must preserve behavior (Liskov Substitution Principle)
What is Liskov’s Substitution Principle (LSP)?
Subtypes must be usable anywhere their supertypes are expected, without altering correctness
Open-Closed Principle (OCP)?
Software entities should be open for extension but closed for modification
Single Responsibility Principle (SRP)?
A class should have only one reason to change (one responsibility)
Dependency Inversion Principle (DIP)?
A: Code against abstractions, not concrete implementations
Which pattern solves “choose an algorithm at runtime”?
Strategy
Which pattern ensures only one instance of a class exists?
Singleton
Which pattern allows attaching observers dynamically to be notified of state changes?
Observer
Which pattern allows adding responsibilities to objects dynamically?
Decorator
Which pattern adapts an existing class to a different interface?
Adapter
What happens if you write AnimalHouse<Dog> house = new AnimalHouse<Animal>();?</Animal></Dog>
Compile-time error: generics in Java are invariant
How can parametric polymorphism prevent runtime ClassCastException?
By enforcing type constraints at compile time (e.g., Printer<String> instead of Printer<object>)</object></String>
What are the responsibilities in MVC?
A: Model = data + logic, View = display, Controller = user interaction. View should not contain business logic.