Object-oriented programming (OOP) interview questions move from core concepts—objects, classes, encapsulation, abstraction, inheritance and polymorphism—to Java rules, design trade-offs, SOLID and practical architecture. Use these 49 answers to revise the definitions, see how the ideas fit together in an order system, and practise explaining not just what a choice is but when it helps.
OOP foundations
1. What is object-oriented programming?
OOP is a way to organize software around objects that combine related state and behavior. A program can model concepts such as orders, payments or users, then define how those objects collaborate. It is one approach among several; it does not automatically make software faster or easier to maintain.
2. What is an object?
An object is a software bundle of related state and behavior. An order object might hold an identifier and line items and provide operations such as calculating its total. In an object-oriented language, an object may be created from a class or by another mechanism, depending on the language.
3. What is a class?
A class is a blueprint or prototype from which objects are created. It describes the data and operations its instances can have. A class called Order can define common behavior while individual order objects hold different data.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
4. Class vs object: what is the difference?
A class defines a type and its behavior; an object is a particular instance with its own state. If Order is the class, order42 can be one object created from it. A class may define many instances.
5. What are the four pillars of OOP?
The commonly taught four are encapsulation, abstraction, inheritance and polymorphism. They are useful concepts, not a guarantee that every design needs inheritance or that every language implements them in the same way.
6. What is encapsulation?
Encapsulation keeps an object’s state behind a controlled boundary and exposes operations that preserve its rules. For example, an order can prevent callers from setting an arbitrary total; it can calculate the total from its line items instead.
7. Why is encapsulation useful?
It prevents unrelated code from putting an object into an invalid state and gives the object one place to enforce its invariants. If the rule for calculating an order total changes, callers can continue using the same operation rather than updating every place that manipulates the data.
Free tools Windows power users keep installed
One-click scans. No signup required.
8. What is abstraction?
Abstraction presents the essential operations a caller needs while hiding implementation detail. A payment service might expose charge(amount) without requiring the order to know how a particular payment provider communicates or handles its internal steps.
9. Abstraction vs encapsulation: what is the difference?
Abstraction is about the useful contract a caller sees; encapsulation is about protecting the implementation and state behind that contract. In an order system, an interface such as PaymentMethod can abstract over payment options, while each implementation encapsulates its own details. They often work together, but they are not synonyms.
10. What is inheritance?
Inheritance defines a new class from an existing one so the new class can share or specialize behavior. A subclass can extend a superclass, but inheritance should express a genuine “is-a” relationship, not be chosen only as a shortcut for code reuse.
11. What is polymorphism?
Polymorphism lets code work through a shared type while different implementations provide different behavior. An order can call pay() through a payment-method contract; a card or wallet implementation can handle that operation differently. In Java, an overridden instance method is selected based on the runtime object.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
12. What is an interface?
An interface is a contract between a class and the outside world: it specifies operations an implementing class agrees to provide. For example, PaymentMethod can define a payment operation without specifying whether the implementation is a card, wallet or test double.
Rank #2
Relationships, reuse and dependencies
13. Association vs aggregation vs composition?
These describe relationships between objects, with different implications for ownership. Association means objects are related; aggregation is commonly used for a looser whole–part relationship in which the part can exist independently; composition suggests stronger ownership, where the part’s lifecycle is tied to the whole. Exact terminology and enforcement vary by language and modeling notation.
14. Composition vs inheritance?
Inheritance reuses or specializes behavior by defining a subtype; composition builds behavior by holding references to collaborators and delegating work to them. Composition often limits coupling and makes implementations easier to swap, while inheritance can be a clear fit for a stable, genuine subtype relationship. Deep inheritance trees can make changes and behavior harder to trace.
15. What are IS-A and HAS-A relationships?
“IS-A” describes a subtype relationship: a card payment method is a payment method. “HAS-A” describes a collaborator or part: an order has line items. If a proposed subclass cannot safely stand in for its parent, the IS-A relationship is probably misleading.
16. What is coupling?
Coupling is the degree to which one component depends on another component’s details. Code that depends on a small interface is generally less coupled to a specific implementation than code that constructs and calls a concrete provider directly. Some dependency is unavoidable; the goal is to keep changes from spreading unnecessarily.
17. What is cohesion?
Cohesion describes how closely the responsibilities within a module belong together. A class that validates an order’s items and calculates its total has related responsibilities; adding email delivery, database migration and unrelated reporting can turn it into a scattered, hard-to-change class.
18. What is dependency injection?
Dependency injection supplies an object with the collaborators it needs instead of having it create them internally. An order-processing service can receive a PaymentMethod through a constructor. This makes the dependency visible and allows tests or other environments to provide a different implementation.
19. Why program to an interface?
Depending on a contract rather than a concrete class can let callers use alternative implementations without changing their own logic. It also creates a useful seam for testing. An interface is not automatically beneficial, though: adding one for a single trivial implementation can add indirection without solving a real change or testing need.
20. What is delegation?
Delegation is when an object forwards a task to a collaborator that handles it. An order service can delegate payment processing to a payment method rather than implementing every payment option itself. Delegation is a common way to use composition.
21. When is inheritance appropriate?
Use inheritance when the subtype truly satisfies the parent contract and shared behavior belongs naturally in the hierarchy. Consider composition when behavior needs to vary independently, when the relationship is not a genuine subtype, or when a hierarchy would grow deep and rigid. A good interview answer names the trade-off rather than treating either choice as universal.
Java object-oriented behavior
22. Method overloading vs overriding?
Overloading uses the same method name with different parameter lists, usually within one type; the compiler selects the applicable overload from the declared argument types. Overriding replaces an inherited instance method implementation with a compatible implementation in a subclass; runtime dispatch can select that implementation based on the object’s actual class.
23. Can static methods be overridden?
No. Static methods belong to the class rather than being dispatched on an instance. A subclass can declare a static method with the same signature, which hides the superclass method; which one is called depends on the reference’s compile-time type, not runtime polymorphism.
Recommended Free Tools
24. Can private methods be overridden?
No. A private superclass method is not accessible to the subclass and is not inherited as an overridable method. A same-named method declared in the subclass is a separate method, not an override.
25. What is constructor chaining?
Constructor chaining is the process of one constructor invoking another to initialize an object. In Java, a constructor can invoke another constructor in the same class using this(...), or invoke a superclass constructor using super(...). Such a constructor invocation must be the first statement in the constructor.
26. Are constructors inherited?
No. Constructors are not inherited by subclasses. A subclass constructor can invoke a superclass constructor; if it does not explicitly choose one, Java attempts to invoke the superclass’s no-argument constructor. If no accessible no-argument constructor exists, the subclass must explicitly invoke an accessible superclass constructor.
27. What are Java access modifiers?
public makes a member broadly accessible; protected permits access within its package and, subject to Java’s rules, from subclasses; package-private (no modifier) permits access within the same package; and private restricts access to the declaring class. Use the narrowest access that supports the intended API.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match28. What is upcasting?
Upcasting treats a subclass object as a superclass or interface type, such as assigning a CardPayment instance to a PaymentMethod variable. It is generally implicit and lets client code work through the shared contract. Overridden instance methods still dispatch to the runtime object’s implementation.
29. What is downcasting?
Downcasting converts a reference typed as a superclass or interface to a more specific subtype. It can fail at runtime if the object is not actually an instance of the target type, so use it only when the subtype is known or checked. Prefer adding the needed behavior to a contract over repeated casts when possible.
30. When should instanceof be used?
Use it when behavior genuinely depends on a runtime type and there is no better polymorphic contract for the operation. Check the type before downcasting to avoid a ClassCastException. A long chain of type checks can signal that behavior belongs in overridden methods or a more suitable interface.
Rank #4
31. What is an abstract class?
An abstract class cannot be instantiated directly. It can provide shared implementation and state while requiring subclasses to implement abstract operations. Use it when related subclasses share a meaningful base implementation or state, rather than merely to group unrelated types.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →32. Abstract class vs interface?
An abstract class can hold instance state and provide constructors and shared implementation, but Java classes have only one direct superclass. An interface defines a contract that a class can implement alongside other interfaces; modern Java interfaces can also include certain implemented methods. Choose based on whether you need a shared class implementation or a capability contract, not on a rule that one is always better.
33. What are final classes and methods?
A final class cannot be subclassed. A final method cannot be overridden in a subclass. These declarations constrain extension, which can protect intended behavior but also reduce flexibility for specialization and testing.
34. What are covariant return types?
When overriding a method, Java permits the overriding method to return a more specific reference type than the method in the superclass, provided it is a subtype of the original return type. This lets callers of the subclass receive the more specific result without changing the broader contract.
35. What is virtual method invocation?
For an overridable instance method, Java selects the implementation from the runtime class of the referenced object. If a PaymentMethod variable refers to a CardPayment object, calling an overridden payment operation invokes the card implementation. Static methods and fields do not use this same runtime dispatch.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteSOLID principles and design patterns
36. What are the SOLID principles?
SOLID is a set of design guidelines: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation and Dependency Inversion. They help reason about change and dependencies; they are not a checklist requiring an interface or class for every operation.
37. Explain Single Responsibility.
A module should have one coherent responsibility, often expressed as one main reason to change. If order calculation and email delivery change for unrelated business reasons, separating them can keep those changes from interfering. Avoid interpreting this as “one method per class.”
38. Explain Open/Closed.
Software entities should be open to extension but closed to modification in the sense that adding a supported variation should not require rewriting stable existing logic. A payment service that calls a PaymentMethod contract can accept a new implementation without accumulating provider-specific branches in the service.
39. Explain Liskov Substitution.
A subtype should be usable wherever its base type is expected without breaking the base type’s promises. If a subclass rejects inputs the parent contract accepts or changes expected behavior, callers cannot safely substitute it. This is why a plausible-sounding “is-a” relationship needs to hold behaviorally, not just by name.
Best Value
40. Explain Interface Segregation.
Clients should not be forced to depend on operations they do not use. Prefer focused contracts—for example, separate payment and refund capabilities if some payment methods cannot refund—instead of one oversized interface with irrelevant or unsupported methods.
41. Explain Dependency Inversion.
High-level policy should depend on abstractions rather than low-level implementation details, and both should be arranged around stable contracts. An order workflow can depend on a payment interface; a provider-specific adapter implements it. This makes provider changes less likely to alter the business workflow.
42. What is the Factory pattern?
A factory centralizes object creation when construction details or implementation choice should be separated from callers. For example, a factory can choose a payment adapter from configuration. It is useful when that decision has complexity; a factory that merely wraps an obvious constructor can be needless indirection.
43. What are Strategy and Observer patterns?
Strategy encapsulates interchangeable algorithms behind a common contract, such as different shipping-cost calculations. Observer lets interested objects receive notifications when a subject changes, such as notifying downstream components after an order is placed. Both can reduce hard-coded dependencies, but add coordination and lifecycle concerns that should be justified by actual variation.
44. When does a design pattern add needless complexity?
A pattern is overkill when it introduces extra types, indirection or lifecycle rules without a real variation, reuse or testing problem. Start with the simplest design that expresses the requirements; add a pattern when there is a concrete change seam, not just to make the design sound sophisticated.
Practical and senior-level questions
45. How would you model an order or payment system with OOP?
Keep the example small and put rules with the data they protect. For instance:
import java.math.BigDecimal;
import java.util.List;
interface PaymentMethod {
void charge(BigDecimal amount);
}
final class Order {
private final List<BigDecimal> lineAmounts;
Order(List<BigDecimal> lineAmounts) {
this.lineAmounts = List.copyOf(lineAmounts);
}
BigDecimal total() {
return lineAmounts.stream()
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
void payWith(PaymentMethod method) {
method.charge(total());
}
}
The order owns its line amounts and computes its total; the payment implementation is supplied through a contract. A production system would also define currency, validation, payment outcomes, idempotency and persistence rather than treating this snippet as a complete payment workflow.
46. How do you avoid a God class and tight coupling?
Give each component a coherent responsibility, make dependencies explicit, and use small contracts at genuine boundaries. Move unrelated concerns such as persistence, notification and payment integration behind collaborators. Tests can then replace external dependencies without reproducing the entire system. Do not split classes mechanically if the resulting boundaries are artificial.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match47. How does OOP appear in a Spring-style layered application?
A typical layered design separates a controller or entry point, application/service logic, domain objects and persistence or external-system adapters. Keep business rules in the appropriate domain or service boundary; inject collaborators rather than constructing infrastructure throughout the code. For an external screenshot-capture integration, a small interface could isolate a provider adapter such as ScreenshotNeo from the rest of an application. Its documented API and MCP server are options for developers; the class design should still depend on the contract your application needs.
If you want to try ScreenshotNeo, its free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free.
48. What OOP mistakes do candidates and production teams commonly make?
Common mistakes include confusing abstraction with encapsulation, using inheritance only to reuse code, exposing mutable state without validation, building oversized classes or interfaces, and adding patterns before a real problem exists. In interviews, another mistake is giving a definition without an example or trade-off. In production, watch for boundaries that make tests depend on databases or external services when the behavior under test does not require them.
49. How should a senior candidate answer an OOP question?
Define the term accurately, illustrate it with a small example, state the relevant trade-off, and connect the choice to maintainability, cohesion, coupling, extensibility or testability. For a design question, clarify the requirements and likely changes before choosing a hierarchy or interface. Acknowledge where the design could be simpler and what evidence would justify changing it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




