zoukankan      html  css  js  c++  java
  • 封装

    1.  封装:隐藏类内部细节
    2.  步骤:
             第一步:将属性私有化.(private)
             第二步:提供getter/setter方法(getXxxx(),setXxxx()).
             第三步:在getter/setter中加入控制语句.

    3.  this关键词
           this:表示当前对象.
                 调用属性:this.属性名
                 调用方法:this.方法名();
           this():表示调用构造函数.
           注意:this(),必需写在构造函数的第一行.

    package 第二章;
    
    public class Tm {
        private int th;
        private String tm;
        private String xx;
        private String xx1;
        private String xx2;
        private String xx3;
        
        public Tm(){
            
        }
    
        public int getTh() {
            return th;
        }
    
        public void setTh(int th) {
            this.th = th;
        }
    
        public String getTm() {
            return tm;
        }
    
        public void setTm(String tm) {
            this.tm = tm;
        }
    
        public String getXx() {
            return xx;
        }
    
        public void setXx(String xx) {
            this.xx = xx;
        }
    
        public String getXx1() {
            return xx1;
        }
    
        public void setXx1(String xx1) {
            this.xx1 = xx1;
        }
    
        public String getXx2() {
            return xx2;
        }
    
        public void setXx2(String xx2) {
            this.xx2 = xx2;
        }
    
        public String getXx3() {
            return xx3;
        }
    
        public void setXx3(String xx3) {
            this.xx3 = xx3;
        }
        public void print(){
            System.out.println(th+tm+xx+xx1+xx2+xx3);
        }
    }
    View Code
  • 相关阅读:
    软连接
    libmysqlclient.so.18 not found 的解决方法
    查找某个文件并全部删除
    sudo passwd root:没有相关指令
    智能解析套件
    日志类封装
    windows安装mysql
    xshell报错Socket error Event: 32 Error: 10053
    appium简明教程(8)——那些工具
    appium简明教程(7)——Desired Capabilities详解
  • 原文地址:https://www.cnblogs.com/liumeilin/p/7018604.html
Copyright © 2011-2022 走看看