by Dinesh Thakur

When we want to enter details of several students or workers or patients, then instead of making separate objects by different names, it is better to make an array of object of that class. By making an array of object, we can take the advantage of loops to feed and retrieve data.

       import java.io.*;

        class StudentDetail
          {
             int r,h,e;
             String n;
             StudentDetail()
             throws IOException
                {
                    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
                    String s;
                    System.out.println("Enter Roll Number : ");
                    s=bf.readLine();
                    r=Integer.parseInt(s);
                    System.out.println("Enter Name of Student : ");
                    n=bf.readLine();
                    System.out.println("Enter Hindi Marks : ");
                    s=bf.readLine();
                    h=Integer.parseInt(s);
                    System.out.println("Enter English Marks : ");
                    s=bf.readLine();
                    e=Integer.parseInt(s);
               }
                   void ShowDetail()
                     {
                         System.out.println("Roll :"+ r);
                         System.out.println("Name : "+n);
                         System.out.println("Hindi :"+h);
                         System.out.println("English :"+e);
                     }
         }
                  class ArrayOfObjects
                     {
                         public static void main(String args[])
                            {
                                 int i;
                                 try
                                  {
                                       StudentDetail k[]=new StudentDetail[3];
                                       System.out.println("Enter the Details of Three Students : ");
                                       for(i=0;i<=2;i++)
                                           {
                                               k[i]= new StudentDetail();
                                           }
                                               System.out.println("The Details of Three Students Entered are : ");
                                               for(i=0;i<=2;i++)
                                                   {
                                                       k[i].ShowDetail();
                                                   }  
                                   }
                                         catch(IOException e){}
                            }
                   };

Array of Objects