package java面向对象;

/*
this关键字的使用,this表示当前创建好的对象
*/

public class TestThis {

int a,b,c;
public TestThis(int a,int b){
//1、通过this来区分局部变量和成员变量
this.a=a;
this.b=b;
}
public TestThis(int a,int b,int c){
//2、通过this调用上面的构造方法,必须放在第一句
//3、this不能在static静态方法中使用
this(a,b);
this.c=c;
}
void sing(){

}
void eat(){
this.sing();//调用本类中sing(),可以不写this
System.out.println("哈哈哈");
}
public static void main(String[] args) {
TestThis tt=new TestThis(20,30);
tt.eat();
}
}

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2022-01-06
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-07-22
猜你喜欢
  • 2021-04-18
  • 2021-07-14
  • 2021-05-17
  • 2021-09-02
  • 2022-12-23
  • 2022-03-10
  • 2022-12-23
相关资源
相似解决方案