1.this点取属性
public class Student {
String name;
public Student(String name) {
this.name = name;
}
public void run() {
String name="小小";
System.out.println(name);
System.out.println(this.name + "跑步");
}
}
public class Test02 {
public static void main(String[] args) {
Student student=new Student("晓晓");
student.run();
}
}
2.this点取方法
public class Student {
String name;
public Student(String name) {
this.name = name;
}
public void swim(){
System.out.println(name+"游泳");
}
public void run() {
//this.swim()和swim()一样
this.swim();
System.out.println(name+"跑步");
}
}
public class Test02 {
public static void main(String[] args) {
Student student=new Student("晓晓");
student.run();
}
}
3.this()调用构造方法
public class Student {
public Student(){
System.out.println("构造方法");
}
public Student(String name) {
this();
System.out.println(name);
}
}
public class Test02 {
public static void main(String[] args) {
Student student=new Student("晓晓");
}
}