공부기록1 [Java] super 와 this 의 차이 Java에서는 super, super() 혹은 this, this() 를 자주 볼 수 있다. this - 현재 클래스의 멤버변수를 지정할 때 사용 public class Ex{ private int weight; private int height; public void set(int weight, int height){ this.weight = weight; this.height = height; } } 위 처럼 클래스 안에서 해당 멤버변수에 값을 설정하기 위해 this를 사용하였다. 또한 매개변수와 클래스 내의 멤버변수를 구분하기도한다. (this를 붙이면 클래스 멤버변수, 안붙이면 매개변수) this() - 현재 클래스 안에 정의된 다른 생성자를 부를 때 사용 public class Ex{ priva.. 2023. 10. 13. 이전 1 다음