4.8 this关键字

时间:2022-07-25
本文章向大家介绍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();
	}
}