首页 > 其他 > 详细

20161201

时间:2016-12-02 02:40:11      阅读:179      评论:0      收藏:0      [点我收藏+]

this关键字使用方法

this.属性  或者 this.方法   this指代当前对象

this()  在一个构造方法中调用本类中的另一个构造方法,实现构造方法代码的复用

this()只能写在构造方法内的第一句 

public class Person {

  private String name;

  private int age;

  private boolean gender;//性别male female

  public Person(){
    this("匿名");
  }

  public Person(String name){
    this(name,18,true);//代表调用本类的另一个构造方法,只能写在一个构造里面且只能是第一句!
  }

  public Person(String name, int age){
    this(name,age,true);
  }

}

20161201

原文:http://www.cnblogs.com/ljwa/p/6123929.html

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