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", 65000);
// 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 available 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;
}虚拟机里更改Ubuntu的分辨率Ubuntu 10.04下Android编译环境搭建相关资讯 Linux函数
- Linux C语言中gotoxy函数 (04月11日)
- Linux进程之Fork函数 (04/16/2015 08:48:35)
- Linux中getrusage的使用 (11/08/2014 07:07:38)
| - Linux内核中min和max的实现 (03月03日)
- Linux下mmap函数的一个练习 (01/19/2015 21:11:21)
- Linux下confstr与uname函数_获取C (10/28/2014 20:23:36)
|
本文评论 查看全部评论 (0)