Adding Different Class Object in one Array

Introduction

This article gives an idea, how to hold the object of different classes in array of another class.

Suppose I have three classes Bird, Human and Fish and another class is Holder to hold the object of those three classes (Bird, Human, fish).

arrayclass1.gif

Object Holder Class

arrayclass2.gif

But we can't create object array class with the reference of bird, human and fish class. Because we were the error “Can Not Implicitly Convert type Bird to System. Array” for solve this error I Used interface.

Suppose I have one Interface and it define one method Talk ().which implements all those three classes (Bird, Human, Fish) like.

arrayclass3.gif

Now in holder class we can hold the all object of different classes in array variable Of Interface IAnimal Type by below code:

arrayclass4.gif