What is the difference btn inheritance and aggregation when do u use one another?
Printable View
What is the difference btn inheritance and aggregation when do u use one another?
Inheritance is used for an IS-A relationship.
Aggregation is used for a HAS-A relationship.
EG:
Cars, Scooters are vehicles. (Inheritance)
Car has a steering, wheel etc. (Aggregation)
In Inheritance, a class inherits the properties of the base class.
In Aggregation, a class uses the properties of some other class.
Regards,
Sahil.
Inheritance is the process where one object acquires the feature of another
object. It depicts is-a relationship. Like car is-a vehicle.
Aggregation deals with Has-a relationship. For example car has engine..
here engine is an object which is a part of another object called car.
Regards,
Krishna.