Tell me about OOP concepts in Java and give some examples.
1Times asked
Oct 2026Last seen
Oct 2026First seen
💡 Model Answer
Object‑Oriented Programming (OOP) in Java is built around four core principles:
- Encapsulation – Bundling data (fields) and behavior (methods) into a single class and restricting direct access to the data. Example: A
BankAccountclass exposesdeposit()andwithdraw()methods while keeping the balance field private.
- Inheritance – Creating a new class (subclass) that inherits fields and methods from an existing class (superclass). Example:
SavingsAccountextendsBankAccountand adds an interest‑rate field.
- Polymorphism – The ability to treat objects of different subclasses through a common interface or superclass, allowing the same method call to execute different implementations. Example: A
Listinterface withArrayListandLinkedListimplementations; callingadd()on aListreference invokes the appropriate subclass method.
- Abstraction – Hiding complex implementation details behind simple interfaces or abstract classes. Example: An
Animalabstract class defines an abstractmakeSound()method; concrete classes likeDogandCatprovide specific implementations.
These concepts enable modular, reusable, and maintainable code. For instance, you can define an interface Shape with a draw() method, then implement Circle, Rectangle, and Triangle classes that each provide their own draw() logic, allowing a graphics engine to render any shape polymorphically.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500