IS-A and Has-A are two important relationships in Object-Oriented Programming that help model real-world relationships between classes. IS-A is achieved through inheritance, while Has-A is achieved through composition or aggregation.
An IS-A relationship exists when a subclass is a type of its superclass.
A Dog IS-A Animal.
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog is barking");
}
}Here, Dog inherits the properties and behaviors of Animal because a Dog is an Animal.
A Has-A relationship exists when one class contains an object of another class.
A Car HAS-A Engine.
class Engine {
void start() {
System.out.println("Engine Started");
}
}
class Car {
private Engine engine = new Engine();
void startCar() {
engine.start();
}
}Here, Car uses an Engine object because a Car has an Engine.
A concise interview answer is
IS-A represents inheritance, where a subclass is a specialized form of a superclass, such as Dog IS-A Animal. Has-A represents composition, where one class contains another class as a member, such as Car HAS-A Engine. In modern application design, Has-A relationships are generally preferred because they provide better flexibility and loose coupling.
Last updated: 16 July 2026
Previous question: What is the difference between association, aggregation, and composition in Java?
Next question: How does method overloading relate to polymorphism?