首页 > 其他 > 详细

新的学期要继续学习喽

时间:2019-03-12 21:39:55      阅读:131      评论:0      收藏:0      [点我收藏+]


public class TestThis {
int a,b,c;//成员变量abc

TestThis(int a,int b){//局部变量ab
this.a = a;//用this来区分吧成员变量a赋值到局部变量a,就近原则(当前对象离谁近指的是谁)
this.b = b;

}
TestThis(int a,int b,int c){
this(a,b);//用this在构造器中调用另一个构造器的使用,不能够自己调用自己且,必须放在构造方法的第一句
this.c = c;
}
void sing(){

}
void eat(){
this.sing();//调用本类中的sing()
System.out.println("你妈妈喊你回家吃饭");
}

public static void main(String[] args){//this不能够使用在static方法中
TestThis hi = new TestThis(2,3);
hi.eat();

}

}

新的学期要继续学习喽

原文:https://www.cnblogs.com/dream2060/p/10519819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!