日期:2014-05-20  浏览次数:20772 次

很纠结的一个问题。。。
现在有两个包,下面的是第一包,在第二个包里看不到GraduateStudent类...
Java code

package com.neusoft.vo;
     public class Student {
     public String name;
     public String sex;
     public int age;
     public String schoolName;

     public  Student (){}
     public  Student(String name,String sex,int age,String schoolName){
         this.name=name;
         this.sex=sex;
         this.age=age;
         this.schoolName=schoolName;
      }

     class GraduateStudent extends  Student {
        String specialityl;
        String teacher;
   
      public GraduateStudent(){}
      public GraduateStudent(String name,String sex,int age,String schoolName,String specialityl,String teacher){
             super.name=name;
             super.sex=sex;
             super.age=age;
             super.schoolName=schoolName;
             this.specialityl=specialityl;
             this.teacher=teacher;
        }



Java code


package test;
import com.neusoft.vo.*;
public class TestStudentAndGraduateStudent extends Student {
    public static void main(String[] args) {
        Student zhou[]=new Student[2];
        zhou[0]=new Student("赵大","男",19,"华南理工大学");
        //不知道下面这样写可不可以,是Student 的引用然后是GraduateStudent类型的数组。应该行的吧
        zhou[1]=new GraduateStudent("孙三","男",25,"华南师范大学","教育学","李四");


总是显示GraduateStudent不可见。。。把它修饰成public 的话,Student类又看不到了。。。
折磨了很久都不懂。。
刚学啊。。很多都不懂。。

请大牛们解答。。。

------解决方案--------------------
你的GraduateStudent是内部类啊....
package com.neusoft.vo;
public class Student {
public String name;
public String sex;
public int age;
public String schoolName;

public Student (){}
public Student(String name,String sex,int age,String schoolName){
this.name=name;
this.sex=sex;
this.age=age;
this.schoolName=schoolName;
}
}
//移到外边来声明
class GraduateStudent extends Student {
String specialityl;
String teacher;
 
public GraduateStudent(){}
public GraduateStudent(String name,String sex,int age,String schoolName,String specialityl,String teacher){
super.name=name;
super.sex=sex;
super.age=age;
super.schoolName=schoolName;
this.specialityl=specialityl;
this.teacher=teacher;
}
------解决方案--------------------
GraduateStudent是Student类的内部类,你把这两个类分别放在两个文件中(还在同一个包里)试试
------解决方案--------------------
把它写成两个类
Java code

package com.neusoft.vo;
     public class Student {
     public String name;
     public String sex;
     public int age;
     public String schoolName;

     public  Student (){}
     public  Student(String name,String sex,int age,String schoolName){
         this.name=name;
         this.sex=sex;
         this.age=age;
         this.schoolName=schoolName;
      }

------解决方案--------------------
不可能吧,但是
Java code

            System.out.println("姓名:"+zhou[i].name+"\n"+"性别:"+zhou[i].sex+"\n"+"年龄:"+zhou[i].age+"\n"+"学校:"+zhou[i].schoolName+"\n"+"专业:"
                                 +zhou[i].specialityl+"\n"+"导师:"+zhou[i].teacher);

------解决方案--------------------