Java · OOP, JVM and backend craft
What are the core object-oriented principles in Java?
Short answer
The four OOP pillars are encapsulation, abstraction, inheritance and polymorphism. Together they let you hide implementation details and program against stable interfaces.
Encapsulation hides internal state behind methods and enforces invariants. Abstraction exposes a simplified model and hides unnecessary detail. Inheritance expresses an is-a relationship. Polymorphism lets one reference invoke behaviour that depends on the runtime type.
public final class Account {
private long balance;
public void deposit(long amount) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be positive");
}
balance += amount;
}
public long balance() {
return balance;
}
}How the principles reinforce each other
- Encapsulation makes abstraction possible because callers depend on behaviour, not fields
- Inheritance can share a contract, but it also creates coupling
- Polymorphism lets new implementations plug in without changing callers
- Composition is often a safer reuse mechanism than inheritance
Encapsulation and abstraction are related but not identical. Encapsulation is about access control and invariants. Abstraction is about choosing the right model and hiding accidental complexity. A class can have private fields and still expose a poor abstraction.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between encapsulation and abstraction?
- 2How does polymorphism depend on inheritance or interfaces?
- 3Why is composition often preferred over inheritance?
- 4Which SOLID principle follows most directly from abstraction?
Say it in the interview
Encapsulation keeps state private and enforces invariants through methods. Abstraction exposes a useful model while hiding implementation detail, and polymorphism lets a reference dispatch to the runtime type. I rely most on encapsulation and abstraction because they let me change internals safely. I use inheritance sparingly and prefer composition when the relationship is really has-a.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Java mock interview and get scored feedback on depth, clarity and confidence.