Week 12

Give an example of polymorphism:

Basically polymorphism is shapeshifting objects where one many different objects can be under one name. Suppose there is a base class called Fruit, and three other derived classes that extend Fruit class called Apple, Orange, and Strawberry. Theses classes have their own constructors and thus when you create a Fruit object you can instantiate an Apple, Orange, or Strawberry object. This examplifies polymorphism because a fruit object can be any of those other fruits. The declarations for these objects may look like :

Fruit apple1 = new Apple();
Fruit orange1 = new Orange();
Fruit strawberry = new Strawberry();

Now suppose the base class had methods such as isRipe(), ripen(), poison() or isPoisoned(), then its derived classes would inherit these methods.

After the learning this week, can you identify the difference between Abstract classes and interfaces:

Abstract classes do not handle multiple inheritances, can't be instantiated, but you are able to have implemented methods in abstract methods. On the other hand, Interfaces do allow for multiple inheritances, but do not allow for any implementation details and all fields must be public static final.