July 2019
Intermediate to advanced
410 pages
10h 32m
English
Inheritance polymorphism allows for functionality to be determined at runtime in a similar way to an interface but applies to class inheritance. In our example, a pet can be fed, so we can define this as having a new Feed(IPetFood) method, which uses the interface that was defined previously:
public virtual void Feed(IPetFood food){ Eat(food);}protected void Eat(IPetFood food){ _hunger -= food.Energy;}
Read now
Unlock full access