标签:class 知识点 span col 一点 不能 out strong main方法
1.this代表的是当前对象的引用。通常而言那个对象调用这个方法,这个方法中的this就代表那个对象。
public vide detail(){ System.out.println(this.nam);//通常this都可以省略 }
2.为什么构造方法也会有this呢?按理来说此时还没有对象啊?怎么会有this关键字呢?
new Student();当使用new的时候,就会创建出一个对象,然后在往对象的属性中添加值,这样就可以有this了。
public Student(String name) { this.name = name; }
3.this关键字不能使用在静态方法中。
public static void main(String[] args) { Student student = new Student("张三"); System.out.println(this.name); //这句话是错的,this与我们创建的student一点关系都没有。谁调用这个main方法,这个main方法就是谁。 }
标签:class 知识点 span col 一点 不能 out strong main方法
原文地址:https://www.cnblogs.com/pogusanqian/p/12744265.html