Java – Objects & Relations

Objects & Relations: Three most common relationships among classes in Java:

Use-A relation: When we create an object of a class inside a method of another class, this relationship is called dependence relationship in Java, or simply Uses-A relationship.

BankEmployee use Customer Account objects to perform their transactions

Is-A relation: Is-A relationship defines the relationship between two classes in which one class extends another class.

Every Employee is a Person
Every Manager is an Employee

Has-A relation: When an object of one class is created as data member inside another class, it is called association relationship in java or simply Has-A relationship.

Every Person object Has Address object

There are two types of Has-A relationship that are as follows:

Aggregation :            

  • Establish a weak Has-A relation between objects.
  • For example, Library Has Students.
  • If we destroy Library, Still student objects alive.

Composition :            

  • Establish a Strong Has-A relation between objects.
  • For example, Person Has Aadhar.
  • If the Person died, Aadhar will not work there after.

Scroll to Top