public class StaticTest
{
public static void main(String[] args)
{
//fill the staff array with three Employee objects
Employee[] staff = new Employee[3]; staff[0] = new Employee("tom", 40000);
staff[1] = new Employee("Dick", 60000);
staff[2] = new Employee("Harry", 6500); //print out information about all Employee objects
for (Employee e : staff)
{
e.setId();
System.out.println("name=" + e.getName()
+ ",id=" + e.getId()
+ ",salary=" + e.getSalary());
}
int n = Employee.getNextId(); // calls static method
System.out.println("Next available id=" + n);
}
}class Employee
{
public Employee(String n, double s)
{
name = n;
salary = s;
id = 0;
}
public String getName()
{
return name;
} //public double getSalary()
{
return salary;
}
public int getId()
{
return id;
}
public void setId()
{
id = nextId; //set id to next availab id
nextId++;
} public static int getNextId()
{
return nextId; //returns static field
} public static void main(String[] args) // unit test
{
Employee e = new Employee("harry", 50000);
System.out.println(e.getName() + " " + e.getSalary());
}
private String name;
Private double salary;
private int id;
private static int nextId = 1;
}这段代码是我照书敲的,没发现什么错误,但是系统提示红色的那行需要标识符!!
请个个姐姐们帮帮小弟啊
{
public static void main(String[] args)
{
//fill the staff array with three Employee objects
Employee[] staff = new Employee[3]; staff[0] = new Employee("tom", 40000);
staff[1] = new Employee("Dick", 60000);
staff[2] = new Employee("Harry", 6500); //print out information about all Employee objects
for (Employee e : staff)
{
e.setId();
System.out.println("name=" + e.getName()
+ ",id=" + e.getId()
+ ",salary=" + e.getSalary());
}
int n = Employee.getNextId(); // calls static method
System.out.println("Next available id=" + n);
}
}class Employee
{
public Employee(String n, double s)
{
name = n;
salary = s;
id = 0;
}
public String getName()
{
return name;
} //public double getSalary()
{
return salary;
}
public int getId()
{
return id;
}
public void setId()
{
id = nextId; //set id to next availab id
nextId++;
} public static int getNextId()
{
return nextId; //returns static field
} public static void main(String[] args) // unit test
{
Employee e = new Employee("harry", 50000);
System.out.println(e.getName() + " " + e.getSalary());
}
private String name;
Private double salary;
private int id;
private static int nextId = 1;
}这段代码是我照书敲的,没发现什么错误,但是系统提示红色的那行需要标识符!!
请个个姐姐们帮帮小弟啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货