Composition VS Inheritance

Composition

Java composition is achieved by using instance variables that refers to other objects.

Inheritance

Example

class subClass extends superClass
{
//methods and fields
}

The difference between Composition and Inheritance

The difference between Composition and Inheritance is that with Composition you can reuse code without extending it with Inheritance you must extend the code to reuse classes.

Composition you can use many classes