Skip to content
C

Java Interview Questions

OOP Interview Questions

Object-oriented programming as a paradigm — the four pillars, class relationships, and design guidelines.

Question 1: What is Object-Oriented Programming, and why was it introduced?

Ans

Object-Oriented Programming (OOP) is a way of structuring software around "objects" that bundle together data (state) and the behavior (methods) that operates on that data, rather than organizing a program as a sequence of standalone functions acting on shared data. It was introduced to make large programs easier to reason about, extend, and maintain by modeling real business or domain concepts directly as objects.

Important Point

OOP is a design paradigm, not a language feature tied to one syntax — Java, Python, and C++ all implement it differently.

Question 2: What is composition?

Ans

Composition means building a class using objects of other classes rather than inheriting their implementation.

It is useful when one object "has a" component and the relationship should be replaceable or loosely coupled.

Example

java
class Car { private final Engine engine = new Engine(); }

Important Point

Composition often gives more flexibility than inheritance, but the correct choice depends on the domain.

Question 3: What is aggregation?

Ans

Aggregation is a weaker has-a relationship where the contained object can conceptually exist independently of the container.

It is mainly a modeling concept rather than a special Java keyword.

Example

text
Department -> Employee objects Employees can exist independently of a particular Department

Important Point

Do not confuse aggregation with Java's syntax; both aggregation and composition can be represented using fields.

Continue Your Preparation