码迷,mamicode.com
首页 > 其他好文 > 详细

面向对象chapter3

时间:2017-06-15 21:48:55      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:reg   logs   步骤   属性   chapter   log   string   turn   setter   

public class Excelle {
    private String type;
    private String id;
    public Excelle(){
        
    }
    public Excelle(String id,String type){
        this.type=type;
        this.id=id;
    }
    public String getType(){
        return type;
    }
    public String getId(){
        return id;
    }
}


public class Regal {
    private String type;
    private String id;
    public Regal(){
        
    }
    public Regal(String id,String type){
        this.type=type;
        this.id=id;
    }
    public String getType(){
        return type;
    }
    public String getId(){
        return id;
    }
}

 

封装
    1.隐藏类内部实现细节(封装)

    2.步骤:
                a.将属性私有化(private
         b.提供getter/setter 方法(getXxx(),setXxx())
         c.在getter/setter中加入控制语句
    3.this 关键词:
        this:表示当前对象
        调用属性:this.属性名
        调用方法:this.方法名();
        this():表示调用构造函数。
        注意:this();必需写在构造函数的第一行。      

 

面向对象chapter3

标签:reg   logs   步骤   属性   chapter   log   string   turn   setter   

原文地址:http://www.cnblogs.com/wangjinshabi250/p/7019734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!