package and import problem
Hello,
I have a problem when I package a file and import the file in another file.
This is my program:
package zyntz;
// the classes in this file are part of this package
import java.util.*;
// import statements come after the package statement
public class Employee
{
public Employee(String n,int a , int b, int c, int d)
{
name = n;
salary = a;
}
//three overloaded constructors
public Employee(String n, double s)
{
name = n;
salary = s;
}
public Employee(double s)
{
//calls the Employee(String, double) constructor
this("Employee #" + nextId, s);
}
//the default constructor
public Employee()
{
//name initialized to ""--see below
//salary not explicitly set--initialized to 0
//id initialized in initialization block
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public int getId()
{
return id;
}
//object initialization block
{
id = nextId;
nextId++;
}
//static initialization block
static
{
Random generator = new Random();//¹¹Ãìû¸öÃæ»úÃýÃú³ÃÃ÷
//set nextId to a random number between 0 and 9999
nextId = generator.nextInt(10000);//·µ»Ã0~9999µÃÃæ»úÃý
}
public void raiseSalary()
{
}
private String name = ""; //instance variable initialization
private double salary;
private int id;
private static int nextId;
//################################################## ###
import zyntz.*;
// the Employee class is defined in that package
public class PackageTest
{
public static void main(String[] args)
{
//because of the import statement, we don't have to
//use com.zyntz.java.Employee here
Employee harry = new Employee ();
//raise salary by 5%
harry.raiseSalary();
//print out information about harry
System.out.println("name=" + harry.getName() + ",salary=" + harry.getSalary());
}
}
But when change the word "*" to "Employee",the program is right!
Please tell me why.
Thank you very much!
Prince
|