package com.corejava;
import java.util.*;
public class Test2
{
private String name;
private double salary;
private int id;
private static int count = 0;
public Test2(String name, double salary)
{
this.name = name;
this.salary = salary;
count++;
id = count;
}
}
主程序为
import com.corejava.*;
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Employee[] student = new Employee[3];
student[0] = new Employee("abc", 200);
student[1] = new Employee("efg", 300);
student[2] = new Employee("opq", 400);
for(Employee i: student)
{
System.out.println("name = " + i.name + "salary = " + i.salary + ", and the id is " + i.getId());
}
}
}