정적 멤버 클래스
주요 특징
예제 (Java)
public class OuterClass {
private static String staticVariable = "Hello";
private String instanceVariable = "World";
// 정적 멤버 클래스
public static class StaticNestedClass {
public void display() {
// 외부 클래스의 static 변수에 접근 가능
System.out.println(staticVariable);
// 외부 클래스의 인스턴스 변수에 직접 접근 불가
// System.out.println(instanceVariable); // 오류 발생
}
}
}
public class Main {
public static void main(String[] args) {
// 정적 멤버 클래스의 객체 생성
OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();
nestedObject.display(); // "Hello" 출력
}
}설명
Last updated