[OOP]Local variables, Parameter variables, Field variables
지역변수(Local Variable) : 로컬 변수는 특정 표현식의 컨텍스트 내에서만 사용할 수 있는 특정 변수 유형이며 해당 변수를 정의하는 함수 내에서만 액세스할 수 있습니다. 로컬 변수는 특정 메소드 내에 해당 데이터만 필요할 때 유용합니다.
Local variables are a specific type of variable that are only available within the context of a particular expression and can only be accessed within the function that defines them. Local variables are useful when you only need that data within a particular expression.
매개변수(Parameter variables) : 매개 변수는 메서드가 호출될 때 메서드에 전달되는 변수입니다. 매개 변수는 선언하는 메서드 내에서만 액세스할 수 있지만 메서드가 호출될 때 매개 변수에 값이 할당됩니다.
A parameter is a variable that is passed to a method when the method is called. Parameters are also only accessible inside the method that declares them, although a value is assigned to them when the method is called. Parameters are also covered in more detail in the text on Java methods
객체형변수(Field variables) :클래스의 멤버로 선언된 변수입니다. OR 메소드/구축자 외부에 선언된 변수이지만 클래스 블록 내부에 선언된 변수입니다. 범위: 자신이 속한 인스턴스가 활성 상태인 동안 생존할 수 있습니다. 로컬 변수: 메서드 또는 특정 문 블럭 내에 선언된 변수입니다.
Field variables that are declared as a member of a class. OR Variables declared outside any method/constructor but inside the class block. Scope: they can live as long as the instance they belong to is active. Local variables: Variables that are declared within a method or a specific block of statements.
변수 | 생성 시기 | 소멸 시기 | 저장 메모리 | 사용 방법 |
클래스 변수 | 클래스가 메모리에 올라갈 때 | 프로그램이 종료될 때 | 메소드 영역 | 클래스이름.변수이름 |
인스턴스 변수 | 인스턴스가 생성될 때 | 인스턴스가 소멸할 때 | 힙 영역 | 인스턴스이름.변수이름 |
지역 변수 | 블록 내에서 변수의 선언문이 실행될 때 | 블록을 벗어날 때 | 스택 영역 | 변수이름 |