日期:2014-05-20 浏览次数:20772 次
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; }
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,"华南师范大学","教育学","李四");
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; }
------解决方案--------------------
不可能吧,但是
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);
------解决方案--------------------