zoukankan      html  css  js  c++  java
  • 面向对象3:封装

     封装
        1.隐藏类内部实现细节(封装)
    
        2.步骤:
                    a.将属性私有化(private)
             b.提供getter/setter 方法(getXxx(),setXxx())
             c.在getter/setter中加入控制语句
        3.this 关键词:
            this:表示当前对象
            调用属性:this.属性名
            调用方法:this.方法名();
            this():表示调用构造函数。
            注意:this();必需写在构造函数的第一行。       
    
    
    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;
        }
    }
  • 相关阅读:
    001 Python网络爬虫与信息提取 课程前序
    004 JQuery (010
    Vuex的元素对象
    003 JQuery (009
    002 JQuery (004
    001 JQuery (001
    Vuex简介
    axios实例与模块封装
    axios拦截器
    015 Javascript(152
  • 原文地址:https://www.cnblogs.com/yangchan250/p/7009572.html
Copyright © 2011-2022 走看看