为何把packageTest.java中的import com.horstmann.core.java.*;改成import com.horstmann.corejava. Employee.java.才能编译通过,//packageTest.javaimport com.horstmann.corejava.*;
public class packageTest
{
public static void main (String[] args)
{
//because of the import statement, we don't have to
//use com.horstmann.corejava.Employee here
Employee harry = new Employee ("Harry Hacker",50000,1989,10,1);
//raise salary by 5%
harry.raiseSalary(5);
//print out information about harry
System.out.println("name="+harry.getName()+",salary="+harry.getSalary());
}
}// Employee.java
package com.horstmann.corejava;
import java.util.*; 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);
// GregorianCalendar uses 0 for January
hireDay = calendar.getTime();
} public String getName()
{
return name;
} public double getSalary()
{
return salary;
} public Date getHireDay()
{
return hireDay;
} public void raiseSalary(double byPercent)
{
double raise = salary * byPercent / 100;
salary += raise;
} private String name;
private double salary;
private Date hireDay;
}
public class packageTest
{
public static void main (String[] args)
{
//because of the import statement, we don't have to
//use com.horstmann.corejava.Employee here
Employee harry = new Employee ("Harry Hacker",50000,1989,10,1);
//raise salary by 5%
harry.raiseSalary(5);
//print out information about harry
System.out.println("name="+harry.getName()+",salary="+harry.getSalary());
}
}// Employee.java
package com.horstmann.corejava;
import java.util.*; 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);
// GregorianCalendar uses 0 for January
hireDay = calendar.getTime();
} public String getName()
{
return name;
} public double getSalary()
{
return salary;
} public Date getHireDay()
{
return hireDay;
} public void raiseSalary(double byPercent)
{
double raise = salary * byPercent / 100;
salary += raise;
} private String name;
private double salary;
private Date hireDay;
}
----------------------------------------
com.horstmann.corejava.Employee有可能Employee不止一个,发生冲突,所以必须要制定到具体的包下才可以!
import com.horstmann.corejava. Employee.java.看来楼主打印出的问题多多呢,
1.在同一包中是不可能有相同的类啦
2.core.java.*;与corejava. Employee.java有什么差别呢,好象多了一个"."吧,注意,不能import(*.java)