代码如下:
//定义一个学生抽象类
abstract class Student{
//定义学生成员变量
private String name;
private int age;
private String team;
//定义学生构造方法
public Student(){}
public Student(String name,int age,String team){
this.name =name;
this.age = age;
this.team= team;
}
//定义方法。
public String getName(){
return name;
}
public void setName(String name){
this.name =name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public String getTeam(){
return team;
}
public void setTeam(String team){
this.team = team;
}
//抽象方法。
public abstract void study();
public abstract void eat();
}
class BasicStudent extends Student{
//定义学生构造方法
public BasicStudent(){}
public BasicStudent(String name,int age,String team){
super(name,age,team);
}
public void study(){
System.out.println("基础班学生学习JavaSE");
}
public void eat(){
System.out.println("不吃就不吃");
}
}
class WorkStudent extends Student{
//定义学生构造方法
public WorkStudent(){}
public WorkStudent(String name,int age,String team){
super(name,age,team);
}
public void study(){
System.out.println("基础班学生学习JavaEE");
}
public void eat(){
System.out.println("爱吃啥吃啥");
}
}
class StudentTest{
public static void main(String[] args){
Student s = new BasicStudent("林青霞",27,"1023班");
System.out.println(s.getName()+"---"+s.getAge()+"---"+s.getTeam());
}
}
|