Packaging
I have a strange problem.
Any one plz help me.
I created a file
Employee.java
package com.horstmann.corejava;
import java.util.*;
public 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;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
private final String name;
private double salary;
private Date hireDay;
}
I compiled it, a class file was created in the directory structure /com/horstmann/corejava/Employee.class
No i have a file
//PackageTest.java
import com.horstmann.corejava.*;
public class PackageTest {
public static void main(String[] args) {
Employee harry = new Employee("Harry Hacker", 50000, 1989, 10, 1);
harry.raiseSalary(5);
System.out.println("name=" + harry.getName() + ",salary=" + harry.getSalary());
}
}
When i compile this file it gives a strange error:
PackageTest.java [24:1] cannot access Employee
bad class file: C:\Documents and Settings\KA17603\Desktop\Core Java 2\Employee.java
file does not contain class Employee
Please remove or make sure it appears in the correct subdirectory of the classpath.
Employee harry = new Employee("Harry Hacker", 50000, 1989, 10, 1);
^
1 error
But when i replace
import com.horstmann.corejava.*; statement to
import com.horstmann.corejava.Employee;
It works fine.
Why is this so?
Can anyone help me!
Regards
Kalyan

