Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 혼자 공부하는 C언어
- 이스케이프 문자
- 알기쉬운 알고리즘
- buffer
- s
- Selection Sorting
- JSON
- insertion sort
- C 언어 코딩 도장
- Algorithm
- datastructure
- stream
- 윤성우 열혈자료구조
- list 컬렉션
- coding test
- R
- Graph
- C programming
- 이것이 자바다
- 윤성우의 열혈 자료구조
- Stack
- Serialization
- 메모리구조
Archives
- Today
- Total
Engineering Note
[Java] 변수의 scope와 static 본문
public class VariableScopeExam{
int globalScope = 10; //인스턴스 변수
static int staticVal = 7; //클래스 변수
public void scopeTest(int value){
int localScope = 20; //지역변수
System.out.println(globalScope);// 전역변수 같은 클래스내에서 사용 가능
}
public static void main(String[] args){
System.out.println(VariableScopeExam.staticVal); // 클래스 변수는 인스턴스화 하지 않고도 사용 가능
System.out.println(globalScope); // 인스턴스 변수는 인스턴스화해야지만 사용가능
}
}
static 변수는 객체를 인스턴스화 하지 않고 사용할 수 있다. VariableScopeExam Class의 선언한 staticVal field는 static으로 선언했기 때문에 main mathod에서 객체를 인스턴스화 하지 않고 사용할 수 있다.
'Programming Language > Java' 카테고리의 다른 글
| Window에 Java 파일 여러개 설치 feat batch (0) | 2022.08.03 |
|---|---|
| [Java] this 키워드 (0) | 2022.08.02 |
| [스프링 입문을 위한 자바 객체 지향의 원리와 이해] 자바와 절차적/구조적프로그래밍 (0) | 2022.04.22 |
| [스프링 입문을 위한 자바 객체 지향의 원리와 이해] 기계어에서 객체 지향 프로그래밍 언어로 (0) | 2022.04.21 |
| Java의 Array (0) | 2021.06.05 |
Comments