课本习题5-2

People.java

public class People {

    int age,leg = 2, hand = 2;
    protected void showPeopleMess() {
    System.out.printf("%d岁,%d只脚,%d只手\t",age,leg,hand);
    }

}

Student.java

public class Student extends People {
    int number;
    void tellNumber() {
    System.out.println("学号:%d\t");
    }
    int add(int x, int y) {
    return x+y;
    }
}

UniverStudent.java



public class UniverStudent extends Student {
    int multi(int x, int y) {
    return x*y;
    }
}

Example5_2.java



public class Exampla5_1 {


public static void main(String[] args) {
    Student zhang = new Student();
    zhang.age=17;
    zhang.number=100101;
    zhang.tellNumber();
    int x=9;
    int y=29;
    System.out.println("会做加法:");
    int result = zhang.add(x, y);
    System.out.printf("%d+%d=%d\n",x,y,result);
    UniverStudent geng = new UniverStudent();
    geng.age=21;
    geng.number=6609;
    geng.showPeopleMess();
    geng.tellNumber();
    System.out.printf("会做加法");
    result=geng.add(x, y);
    System.out.printf("%d+%d=%d\n",x,y,result);
    System.out.printf("会做乘法:");
    result =geng.multi(x, y);
    System.out.printf("%d*%d=%d\n",x,y,result);
}


}

你可能感兴趣的:(课本习题5-2)