新手求教 为什么我的 测试类名字显示的都是null 请教啦。。
1、 定义一个抽象类GeneralPeople,2、 根据抽象类GeneralPeople派生出学生类Student
3、 根据学生类Student派生出大学生类CollegeStudent,
4、建立抽象类GeneralPeople的测试程序,要求建立一个GeneralPeople类型的数组g,任意建立几个Student类型的对象和CollegeStudent类型的对象,将这些对象依次赋值给数组g中的数组元素,用一个循环多态地调用方法disp()
package 默认;
public abstract class GeneralPeople {
private String name;
private String 易做图;
public GeneralPeople() {
super();
}
public GeneralPeople(String name, boolean 易做图) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
if(true)
return "男";
else
return "女";
}
public void setSex(String 易做图) {
this.易做图 = 易做图;
}
public abstract void disp();
{
System.out.println("\n姓名:"+this.getName()+"\n性别:"+this.getSex());
}
}
package 默认;
public class student extends GeneralPeople {
private String school;
public student() {
super();
}
public student(String name, boolean 易做图, String school) {
super(name, 易做图);
this.school = school;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
@Override
public void disp() {
System.out.println("学校:"+this.getSchool());
}
}
package 默认;
public class collegeStudent extends student {
private String specialty;
public collegeStudent() {
super();
}
public collegeStudent(String name, boolean 易做图, String school,
String specialty) {
super(name, 易做图, school);
this.specialty = specialty;
}
public String getSpecialty() {
return specialty;
}
public void setSpecialty(String specialty) {
this.specialty = specialty;
}
public void disp(){
super.disp();
System.out.println("专业:"+this.getSpecialty());
}
}
package 默认;
public class GeneraPeopleTest {
/**
* @param args
*/
public static void main(String[] args) {
GeneralPeople g[]=new GeneralPeople [2];
student st=new student ("小明",true,"软件技术");
st.disp();
collegeStudent c=new collegeStudent ("小明",true,"软件技术","JAVA");
c.disp();
}
}
--------------------编程问答-------------------- 你的GeneralPeople类的抽象方法这么写编译都通不过吧,还能运行得到null? --------------------编程问答-------------------- 这是四个java文件 我写到一起了。。 最后的 是测试类。。怎么办,,?? --------------------编程问答-------------------- package 默认;
public abstract class GeneralPeople {
private String name;
private String 易做图;
public GeneralPeople() {
super();
}
public GeneralPeople(String name, boolean 易做图) {
super();
this.name = name;
}
这super放这儿是什么意思 ?
补充:Java , Eclipse