20161201

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);
  }

}

原文地址:https://www.cnblogs.com/ljwa/p/6123929.html