Array of class object

Arrays in java are capable of storing objects also.
An array of objects is created just like an array of primitive type data items in the following way.
Employee[] staff = new Employee[5];
Here:

  • ->Employee is a class
  • ->staff is an array capable to hold 5 object of class "Employee"

Example:

class      Employee 
{

	int code;
	String Name;
	String Desig;
	double  salary;
	
	void getData(int code,	String Name,	String Desig,double  salary)
	{
	 this.code=code;
	 this.Name= Name;
	 this.Desig=Desig;
	 this.salary=salary;
	}
	
	void Bonus()
	{
		double b;
		System.out.printf("\n====================================================");
		System.out.print("\nEmployee code::"+this.code);
		  System.out.print("\nEmployee Name::"+this.Name);
		  System.out.print("\nEmployee Designation::"+this.Desig);
		  
		  System.out.print("\nSalary::"+this.salary);
		  
		   if( this.salary>=50000)
		   {
			   b= this.salary*.10;
		   }
		   else if(this.salary>=250000)
		   {
			   b= this.salary*.12;
		   }
		   else
		   {
			   b= this.salary*.15;
		   }
		   
		  System.out.print("\nBonus Amount Rs::"+b);
	
	}
}
public class soft 
{
	
	public  static void main(String  args[])
	{
			  
		// Array Of Class Object
				Employee e[]= new  Employee[4];
				
				
				e[0]= new  Employee();
			    e[0].getData(101,"Jokhan", "Manager",50000);
			    
			    e[1]= new  Employee();
			    e[1].getData(102,"Ramgati", "Accountant",35000);
			    
			    e[2]= new  Employee();
			    e[2].getData(103,"Mohsheen Ali", "Analyst",37000);
			    
			    e[3]= new  Employee();
			    e[3].getData(104,"Ganpati", "Peon",7000);
					    
			  for( int x=0; x<e.length;x++)
			  {
				  e[x].Bonus();
			  }
	
	}

}          

arrcl