文件一: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;
}

解决方案 »

  1.   

    抽象类和接口差不多,不能实例化啊,大哥就是刚开始学,理解不够,如果把文件二直接放到文件一就可以顺利通过编译,但是分开放到包里的文件就不行,额求别叫我大哥import java.util.*;
    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;
    }这样就没问题,分开文件就不行
      

  2.   

    抽象类和接口差不多,不能实例化啊,大哥就是刚开始学,理解不够,如果把文件二直接放到文件一就可以顺利通过编译,但是分开放到包里的文件就不行,额求别叫我大哥import java.util.*;
    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的访问权限吧,访问权限的问题
      

  3.   

    抽象类和接口差不多,不能实例化啊,大哥就是刚开始学,理解不够,如果把文件二直接放到文件一就可以顺利通过编译,但是分开放到包里的文件就不行,额求别叫我大哥import java.util.*;
    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的访问权限吧,访问权限的问题
    哦,好的
      

  4.   

    abstract修饰的类是抽象类,这样的类将不能生成对象实例,但可以用于多态;
      

  5.   

    两个不同包的文件访问要public的,你把person和它的子类的权限更改成public就行了,6楼的文件相当于在一个包中的/