Junior OOP

What is the difference between inheritance and composition?

Feature Inheritance Composition

Relationship "is-a" "has-a"

Reuse Derived class reuses base

class

Object contains other

objects

Flexibility Less flexible More flexible

Example:

  • Inheritance → Car is a Vehicle
  • Composition → Car has a Engine

More from C# Programming Tutorial

All questions for this course