Composition is better when objects need to transmute to objects of another class. Inheritance is appropriate when one class extends another class. Conclusion Inheritance has important uses. It provides strong encapsulation of functionality against classes outside its object hierarchy. It promotes reuse by capturing commonalities in a base class and then extending those common features in descendant classes.
Composition also provides encapsulation and reuse.
Encapsulation is stronger in composition, because changes in one class are less likely to ripple throughout an object hierarchy. With inheritance, on the other hand, a change in a base class impacts every class in the hierarchy. Some languages don't provide for inheritance. Visual Basic is a prominent example. Composition can substitute for inheritance generally, but the results are far from pretty.