4.8 this关键字

/**
 * 测试this
 * @author Hank
 * 
 */

/*
创建一个对象分为如下四步:
1.分配对象空间,并将对象成员变量初始化为0或空
2.执行属性值的显示初始化
3.执行构造方法
4.返回对象的地址给相关的变量
*/

public class TestThis {
	int a,b,c;
	
	TestThis(int a,int b){
		this.a = a;
		this.b = b;
	}
	
	TestThis(int a,int b,int c){
		this(a,b);
		this.c = c;
	}
	
	void sing() {
		
	}
	
	void eat() {
		this.sing(); //调用本类中的sing();
		System.out.println("你妈妈喊你回家吃饭!");
	}
	
	public static void main(String[] args) {
		TestThis hi = new TestThis(2,3,4);
		hi.eat();
	}
}

posted @ 2019-06-28 22:37  hank-li  阅读(128)  评论(0编辑  收藏  举报