Object-oriented programming in Java rests on four ideas: encapsulation, inheritance, polymorphism and abstraction. Interviewers ask about them early, so it helps to explain each with a small example.
The four ideas
- Encapsulation: keep fields private and expose them through methods, so the data stays valid.
- Inheritance: a child class reuses the code of a parent, such as Car extending Vehicle.
- Polymorphism: one method name behaves differently for different objects, such as a draw method on a Circle and a Square.
- Abstraction: hide the detail and show only what a user needs, using an interface or abstract class.
How to explain them
Use one real-world example for all four, such as a bank account. Interviewers value a clear example more than a memorised definition.
Learn these in the Java full stack course, and practise with Java streams. Book a free demo class, and ask a counsellor for the current schedule.
