日期:2014-05-20 浏览次数:20690 次
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("abc", 3000, 1999, 10, 12);
// 为什么不这样写成staff[0] = ("abc", 3000, 1999, 10, 12);
//Employee就相当于一个int呀?
int[] array = new int[3];
array[0] = 1; //这里就没有再用new了。
}
}
class Employee
{
public Employee(String n, double s, int year, int month, int day)
{
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month-1, day);
hireDay = calendar.getTime();
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
String name;
double salary;
Date hireDay;
}
Employee[] staff = new Employee[3];是对象数组,新对象肯定要new
int[] array = new int[3];基本数据类型数组,基本数据类型本来就不用new