Tiny Bunny
[Java] 메서드 안에 변수 안 넘겨도 되는 이유? this 키워드와 객체의 역할
·
🛠️Backend/Java | Spring
변수는 어디서 왔을까?class Rectangle { int width = 5; // 멤버 변수 (필드) int height = 10; // 멤버 변수 (필드) int calculateArea() { return width * height; // 🤔 width, height는 어디서 온 거지? }}초보 개발자라면 "어? calculateArea() 메서드에 width와 height를 매개변수로 넘기지 않았는데 어떻게 사용할 수 있지?"라는 의문이 들 수 있습니다.클래스는 하나의 집과 같다class Rectangle { // 이 집 안에 있는 가구들 (멤버 변수) int width = 5; int height = 10; String color ..