Java—this关键字
2021-05-09 04:29
                         标签:span   round   价格   sys   print   访问   函数   private   mod    this:表示本类的属性   Java—this关键字 标签:span   round   价格   sys   print   访问   函数   private   mod    原文地址:https://www.cnblogs.com/erchun/p/13174456.htmlpublic class PhoneClass {
    //属性
    private String model;
    private int price;
    //定义一个构造函数-无参
    public PhoneClass(){
        System.out.println("无参构造函数");
    }
    //定义一个有参构造函数-有参
    public PhoneClass(String model,int prices){
        //本类的属性
        this.model=model;
        //对价格做控制
        if(prices ){
            System.out.println("价格设置不合理");
        }else {
            //价格合理才会去做设置
            //访问本类的属性
            this.price = price;
        }
    }
}