Are Composition and Inheritance the same? If I want to implement the composition pattern, how can I do that in Java?
Composition means HAS A
Inheritance means IS A
Example
: Car has a Engine and Car is a Automobile
In programming this is represented as:
class Engine {} // The Engine class.
class Automobile {} // Automobile class which is parent to Car class.
class Car extends Automobile { // Car is an Automobile, so Car class extends Automobile class.
private Engine engine; // Car has an Engine so, Car class has an instance of Engine class as its member.
}