Sunday, February 25, 2018

Java program : Storing objects in Array

class Animal
{ {System.out.println("Animal");}
}
class Dog extends Animal
{ {System.out.println("Dog");}
}
class DogKid extends Dog
{ {System.out.println("DogKid");}
}
class ArrayInFamily
{       
       
        static void m1()
        {
           Animal[] a=new Animal[3];
          { a[0] = new Animal();
            a[2] = new DogKid();
            for(Animal aa:a )
                {
                    System.out.println(aa);
                }
          }
        } 
        public static void main(String[] args)
        {
                m1();
               
        }   
}   

Thanks
Happy programming!

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...