Advertisement

面向对象技术书面作业3

阅读量:

面向对象编程中的类定义与继承应用

复制代码
    //为Student子类添加两个属性年龄和成绩,
    // 在子类中打印出学生的姓名、性别、年龄及成绩。
    public class Student extends Person{
    private int age;
    private double score;
    
    //构造方法
    public Student(){
    
    }
    public Student(String name,char sex,int age,double score){
        super(name, sex);
        this.age =age;
        this.score =score;
    }
    
    public void print(){
        System.out.println("学生名字是 " + this.getName() + " 是" + this.getSex()
                +"生 , 年龄是 " + this.age + " 岁,成绩是 " + this.score);
    }
    
    //setter and getter
    
    public int getA

全部评论 (0)

还没有任何评论哟~