this关键字相关知识
注意事项和使用细节:
1.this关键字可以用来访问本类的属性、方法、构造器
2.this 用于区分当前类的属性和局部变量
3.访问成员方法的语法:this.方法名(形参列表);
1 public class this{ 2 public static void main (String[] args){ 3 To sal = new To(); 4 sal.find2(); 5 } 6 } 7 8 class To{ 9 //细节:访问成员方法的语法:this.方法名(形参列表) 10 public void find(){ 11 System.out.println("Find()被调用"); 12 } 13 14 public void find2(){ 15 System.out.println("Find2()被调用"); 16 17 //调用本类的find 18 //第一种方法: 19 find(); 20 //第二种方法: 21 this.find(); 22 } 23 }
4.访问构造器语法:this (参数列表):注意:只能在构造器中使用、 this调用本类中的其他构造方法,调用时要放在构造方法的首行。
5.this不能在类定义的外部使用,只能在类定义的方法中使用
想多了都是问题,做多了才是答案

浙公网安备 33010602011771号