Java 변수
발행: (2026년 1월 12일 오후 11:55 GMT+9)
1 min read
원문: Dev.to
Source: Dev.to
자바에서 변수란?
변수는 데이터 값을 저장하는 데 사용되는 컨테이너입니다.
자바의 변수 종류
로컬 변수
예시:
class Test {
void display() {
int number = 10; // local variable
System.out.println(number);
}
}
인스턴스 변수
예시:
class Student {
int id; // instance variable
String name; // instance variable
}
정적 변수
예시:
class College {
static String collegeName = "ABC College";
}
모든 유형을 보여주는 간단한 프로그램
class Example {
int instanceVar = 20;
static int staticVar = 30;
void show() {
int localVar = 10;
System.out.println(localVar);
System.out.println(instanceVar);
System.out.println(staticVar);
}
}