文件一:import java.text.*;
import com.jacket.*;public class mfj {
public static void main(String[] args)
{
person[] people = new person[2];//这里提示the type person is not visible //fill the people array with Student and Employee objects
people[0] = new Employee("Harry Hacker",50000,1989,10,1);//同上的提示
people[1] = new Student("Maria Morris","computer science");//同上提示for(person p:people)//同上提示
{
System.out.println(p.getName() + "," + p.getDescription());
}
}
}文件二:package com.jacket;
import java.util.*;import java.util.GregorianCalendar;abstract class person {
public person(String n)
{
name = n;
}public abstract String getDescription();public String getName()
{
return name;
}private String name;
}class Employee extends person
{
public Employee(String n,double s,
int year,int mouth,int day)
{
super(n);
GregorianCalendar calendar = new GregorianCalendar(year,mouth - 1,day);
hireDay = calendar.getTime();
}public double getSalary()
{
return salary;
}public Date getHireDay()
{
return hireDay;
}public String getDescription()
{
return String.format("an employee with a salary of $%.2f", salary);
}public void rasieSalary(double byPercent)
{
double rasie = salary * byPercent / 100;
salary +=rasie;
}private double salary;
private Date hireDay;
}class Student extends person
{
/**
@param n the student's name
@param m the student's major
*/public Student(String n,String m)
{
//pass n to superclass constructor
super (n);
major = m;
}public String getDescription()
{
return "a student majoring in "+major;
}private String major;
}
import com.jacket.*;public class mfj {
public static void main(String[] args)
{
person[] people = new person[2];//这里提示the type person is not visible //fill the people array with Student and Employee objects
people[0] = new Employee("Harry Hacker",50000,1989,10,1);//同上的提示
people[1] = new Student("Maria Morris","computer science");//同上提示for(person p:people)//同上提示
{
System.out.println(p.getName() + "," + p.getDescription());
}
}
}文件二:package com.jacket;
import java.util.*;import java.util.GregorianCalendar;abstract class person {
public person(String n)
{
name = n;
}public abstract String getDescription();public String getName()
{
return name;
}private String name;
}class Employee extends person
{
public Employee(String n,double s,
int year,int mouth,int day)
{
super(n);
GregorianCalendar calendar = new GregorianCalendar(year,mouth - 1,day);
hireDay = calendar.getTime();
}public double getSalary()
{
return salary;
}public Date getHireDay()
{
return hireDay;
}public String getDescription()
{
return String.format("an employee with a salary of $%.2f", salary);
}public void rasieSalary(double byPercent)
{
double rasie = salary * byPercent / 100;
salary +=rasie;
}private double salary;
private Date hireDay;
}class Student extends person
{
/**
@param n the student's name
@param m the student's major
*/public Student(String n,String m)
{
//pass n to superclass constructor
super (n);
major = m;
}public String getDescription()
{
return "a student majoring in "+major;
}private String major;
}
import java.text.*;public class mfj {
public static void main(String[] args)
{
person[] people = new person[2];
//fill the people array with Student and Employee objects
people[0] = new Employee("Harry Hacker",50000,1989,10,1);
people[1] = new Student("Maria Morris","computer science");
for(person p:people)
{
System.out.println(p.getName() + "," + p.getDescription());
}
}
}abstract class person {
public person(String n)
{
name = n;
}
public abstract String getDescription();
public String getName()
{
return name;
}
private String name;
}class Employee extends person
{
public Employee(String n,double s,
int year,int mouth,int day)
{
super(n);
GregorianCalendar calendar = new GregorianCalendar(year,mouth - 1,day);
hireDay = calendar.getTime();
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public String getDescription()
{
return String.format("an employee with a salary of $%.2f", salary);
}
public void rasieSalary(double byPercent)
{
double rasie = salary * byPercent / 100;
salary +=rasie;
}
private double salary;
private Date hireDay;
}class Student extends person
{
/**
@param n the student's name
@param m the student's major
*/
public Student(String n,String m)
{
//pass n to superclass constructor
super (n);
major = m;
}
public String getDescription()
{
return "a student majoring in "+major;
}
private String major;
}这样就没问题,分开文件就不行
import java.text.*;public class mfj {
public static void main(String[] args)
{
person[] people = new person[2];
//fill the people array with Student and Employee objects
people[0] = new Employee("Harry Hacker",50000,1989,10,1);
people[1] = new Student("Maria Morris","computer science");
for(person p:people)
{
System.out.println(p.getName() + "," + p.getDescription());
}
}
}abstract class person {
public person(String n)
{
name = n;
}
public abstract String getDescription();
public String getName()
{
return name;
}
private String name;
}class Employee extends person
{
public Employee(String n,double s,
int year,int mouth,int day)
{
super(n);
GregorianCalendar calendar = new GregorianCalendar(year,mouth - 1,day);
hireDay = calendar.getTime();
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public String getDescription()
{
return String.format("an employee with a salary of $%.2f", salary);
}
public void rasieSalary(double byPercent)
{
double rasie = salary * byPercent / 100;
salary +=rasie;
}
private double salary;
private Date hireDay;
}class Student extends person
{
/**
@param n the student's name
@param m the student's major
*/
public Student(String n,String m)
{
//pass n to superclass constructor
super (n);
major = m;
}
public String getDescription()
{
return "a student majoring in "+major;
}
private String major;
}这样就没问题,分开文件就不行你去看看java的访问权限吧,访问权限的问题
import java.text.*;public class mfj {
public static void main(String[] args)
{
person[] people = new person[2];
//fill the people array with Student and Employee objects
people[0] = new Employee("Harry Hacker",50000,1989,10,1);
people[1] = new Student("Maria Morris","computer science");
for(person p:people)
{
System.out.println(p.getName() + "," + p.getDescription());
}
}
}abstract class person {
public person(String n)
{
name = n;
}
public abstract String getDescription();
public String getName()
{
return name;
}
private String name;
}class Employee extends person
{
public Employee(String n,double s,
int year,int mouth,int day)
{
super(n);
GregorianCalendar calendar = new GregorianCalendar(year,mouth - 1,day);
hireDay = calendar.getTime();
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public String getDescription()
{
return String.format("an employee with a salary of $%.2f", salary);
}
public void rasieSalary(double byPercent)
{
double rasie = salary * byPercent / 100;
salary +=rasie;
}
private double salary;
private Date hireDay;
}class Student extends person
{
/**
@param n the student's name
@param m the student's major
*/
public Student(String n,String m)
{
//pass n to superclass constructor
super (n);
major = m;
}
public String getDescription()
{
return "a student majoring in "+major;
}
private String major;
}这样就没问题,分开文件就不行你去看看java的访问权限吧,访问权限的问题
哦,好的