首页 > 其他 > 详细

面向对象之继承01

时间:2019-11-20 13:10:42      阅读:80      评论:0      收藏:0      [点我收藏+]

需要了解的知识点
1.清楚继承性的主要作用以及实现
2.继承性的相关限制以及使用规则
继承性的最大特征是解决代码的重用问题
通过简单程序分析,为什么需要继承
要求定义两个描述人与学生的类
Person.java:

class Persion{
    private String name;
    private int age;
    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return this.name;
    }
    public void setage(String age){
        this.age = age;
    }
    public int getage(){
        return this.age;
    }
    public String getInfo(){
        return this.name +" " + this.age;
    }
}
Student.java:
class Student{
    private String name;
    private int age;
    private String school;
    public void setschool(String school){
        this.school = school;
    }
    public String getSchool(){
        return this.school;
    }
    public void setSchool(String school){
        this.school = school;
    }
    public String getName(){
        return this.name;
    }
    public void setage(String age){
        this.age = age;
    }
    public int getage(){
        return this.age;
    }
    public String getInfo(){
        return this.name +" " + this.age;
    }
    
}
以上程序里面出现了代码的重复,在自然的关系上,学生是属于人的,学生的范围更小

面向对象之继承01

原文:https://www.cnblogs.com/anyux/p/11895924.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!