public class Human {标签:JAVA,String,子类,s1,h1,t1,void,父类,public From: https://www.cnblogs.com/txa2003/p/16953934.html
private String name;
private String sex;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
void run(){
System.out.println("跑步使我快乐");
}
}
class Teacher extends Human{
private String add;
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
void run(){
System.out.println("跑步使我健康");
}
}
class Student1 extends Human{
private String classmate;
public String getClassmate() {
return classmate;
}
public void setClassmate(String classmate) {
this.classmate = classmate;
}
void run(){
System.out.println("跑步时我年轻");
}
}
class test{
public static void main(String[] args) {
Human h1 = new Human();
h1.setAge(18);
h1.setName("a");
h1.setSex("男");
h1.run();
System.out.println("他的性别为"+h1.getSex()+"\n他的名字是"+h1.getName()+"\n他的年龄为"+h1.getAge());
Teacher t1 = new Teacher();
t1.setAdd("南方");
t1.setAge(18);
t1.setName("b");
t1.setSex("男");
t1.run();
System.out.println("他的籍贯是"+t1.getAdd()+"\n他的性别为"+t1.getSex()+"\n他的名字是"+t1.getName()+"\n他的年龄为"+t1.getAge());
Student1 s1 = new Student1();
s1.setClassmate("一班");
s1.setAge(18);
s1.setName("c");
s1.setSex("女");
s1.run();
System.out.println("他的班级是"+s1.getClassmate()+"\n他的性别为"+s1.getSex()+"\n他的名字是"+s1.getName()+"\n他的年龄为"+s1.getAge());
}