Source Code : Define array for class

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Define array for class

Define array for class
     
public class EmployeeTest {
  public static void main(String[] args) {
    Employee[] staff = new Employee[3];
    staff[0] = new Employee("Harry Hacker", 3500);
    staff[1] = new Employee("Carl Cracker", 7500);
    staff[2] = new Employee("Tony Tester", 3800);

    for (int i = 0; i < 3; i++)
      staff[i].print();
  }
}

class Employee {
  private String name;

  private double salary;

  public Employee(String n, double s) {
    name = n;
    salary = s;
  }

  public void print() {
    System.out.println(name + " " + salary);
  }
}
           
         
    
    
    
    
  

Thank with us