Java

[Java/기본] This

hhaeri 2020. 11. 1. 18:25

This : 객체 자신의 참조값

package ex03_method;

class Computer {
	String model;
	String manufacturer;
	int price;	
	
	//method
	//1. setInfo
	void setInfo (String model, String manufacturer, int price) {
		this.model = model;
		this.manufacturer = manufacturer;
		this.price = price;
	}
	//2.info
	void info() {
		//System.out.println(this.model); -> 동작은 하나 사용하지 않는 방식
		System.out.println(model);
	}
}
public class Ex05_this {
	public static void main(String[] args) {
		Computer com = new Computer();
		
		com.setInfo("GRAM", "LG", 180);
		com.info();
	}
    

}