Co-Authored By:
Asked by: Fabien Chabner
technology and computing programming languagesHow do has a relationships differ from is a relationships?
Similarly, it is asked, is a Versus has a relationships?
Wherever you see an extends keyword or implements keyword in a class declaration, then this class is said to have IS-A relationship. HAS-A Relationship: Composition(HAS-A) simply mean the use of instance variables that are references to other objects. For example Maruti has Engine, or House has Bathroom.
Similarly, why is composition called a has a relationship and inheritance called an is a relationship?
Inheritance (is-a) relationships are derived child classes that inherit attributes and methods from their parent class. Composition (has-a) relationships are classes whose attributes are comprised of other classes. Each relationship has its advantages and disadvantages.
In Object oriented programming, IS-A relationship denotes “one object is type of another”. IS-A relation denotes Inheritance methodology. In Java, Inheritance can be implemented with extends (in case of class) and implements(in case of interface) keywords. A simple example of IS-A relation : Dell IS-A laptop.