1.定义Person类 属性: 姓名name、性别gender、年龄age、国籍nationality; 方法:吃饭eat、睡觉sleep,工作work。

1.定义Person类 属性: 姓名name、性别gender、年龄age、国籍nationality; 方法:吃饭eat、睡觉sleep,工作work。_第1张图片
1.定义Person类 属性: 姓名name、性别gender、年龄age、国籍nationality; 方法:吃饭eat、睡觉sleep,工作work。_第2张图片
1.定义Person类 属性: 姓名name、性别gender、年龄age、国籍nationality; 方法:吃饭eat、睡觉sleep,工作work。_第3张图片

public class Person {

/*
姓名
*/
private String name;
/*年


* /
private int age;
/

* 国际*/
private String nationality;

public Person() {
}


public Person(String name, int age, String nationality) {
    this.name = name;
    this.age = age;
    this.nationality = nationality;
}


@Override
public String toString() {
    return "Student{" +
            "name='" + name + '\'' +
            ", age=" + age +
            ", nationality='" + nationality + '\'' +
            '}';
}

public void eat(){
    /*
     * 吃方法*/
}
public void sleep(){
    /*睡觉方法*/

}

public void work(){
    /*工作方法*/

}

}

public class Student extends Person {

private String school;
private int stuNumber;

public Student(String 小斌, int i) {
}


@Override
public void work() {
    System.out.println("学生的工作是学习");
    super.work();
}

public Student(String name, int age, String nationality) {
    super(name, age, nationality);
}


public String getSchool() {
    return school;
}

public void setSchool(String school) {
    this.school = school;
}

public int getStuNumber() {
    return stuNumber;
}

public void setStuNumber(int stuNumber) {
    this.stuNumber = stuNumber;
}

}

public class StudentLeader extends Person{

@Override
public void work() {
    System.out.println("学生会的工作是开会");
    super.work();
}

private String job;


public StudentLeader(String 学生会主席) {
}

public StudentLeader(String name, int age, String nationality) {
    super(name, age, nationality);
}


public String getJob() {
    return job;
}

public void setJob(String job) {
    this.job = job;
}

}

public class Worker extends Person {

private String unit;
private  int workAge;


public Worker(String 小名, int i) {
}

public Worker(String name, int age, String nationality) {
    super(name, age, nationality);
}


public String getUnit() {
    return unit;
}

public void setUnit(String unit) {
    this.unit = unit;
}

public int getWorkAge() {
    return workAge;
}

public void setWorkAge(int workAge) {
    this.workAge = workAge;
}

@Override
public void work() {
    System.out.println("工人的工作是盖房子");
    super.work();
}

}

public static void main(String[] args) {

    Student s = new Student("小李",2016094949);
    s.eat();
    s.sleep();

    s.work();

    Worker w = new Worker("大力士",165464);
    w.work();

    StudentLeader st = new StudentLeader("学生会主席");

    st.work();

你可能感兴趣的:(java,android,开发语言)