3-this关键字

1.表示类中的属性和调用方法

 package com.example;

 /**
* Created by Y on 16/4/13.
*/
public class People {
private String name;
private int age; public void setName(String name) {
this.name = name;
} public String getName() {
return name;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
}
public void tell(){
System.out.println("name is:"+this.getName()+"age is :"+this.getAge());
}
}

People

2.调用本类中的构造方法

 package com.example;

 /**
* Created by Y on 16/4/13.
*/
public class People {
private String name;
private int age;
public People(){
System.out.println("这是无参数构造方法!");
}
public People(String name,int age){
this();
this.name = name;
this.age = age;
}
}

People

3.表示当前类的对象

 package com.example;

 /**
* Created by Y on 16/4/13.
*/
public class People {
public void tell(){
System.out.print(this);
}
}

People

上一篇:Sqlserver 笔记 持续更新


下一篇:Spark架构