This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch09.sec03.exam02; | |
public class A { | |
//정적 멤버 클래스 | |
static class B { | |
// 중첩 클래스로서 특정클래스와만 관게를 맺고, 외부에 감춤으로써 코드 복잡성 감소 할 수 있음. | |
//인스턴스 필드 | |
int field1 = 1; | |
//정적 필드(Java 17부터 허용) | |
static int field2 = 2; | |
//생성자 | |
B() { | |
System.out.println("B-생성자 실행"); | |
} | |
//인스턴스 메소드 | |
void method1() { | |
System.out.println("B-method1 실행"); | |
} | |
//정적 메소드(Java 17부터 허용) | |
static void method2() { | |
System.out.println("B-method2 실행"); | |
} | |
} | |
} | |
public class AExample { | |
public static void main(String[] args) { | |
//B 객체 생성 및 인스턴스 필드 및 메소드 사용 | |
A.B b = new A.B(); | |
System.out.println(b.field1); | |
b.method1(); | |
//B 클래스의 정적 필드 및 메소드 사용 | |
System.out.println(A.B.field2); | |
A.B.method2(); | |
} | |
} |
반응형
'Programming > 자바(java) - Web, Mobile' 카테고리의 다른 글
자바(java)/ StringBuilder 클래스 (0) | 2023.07.14 |
---|---|
자바(java)/ byte배열 문자 변환(네트워크 통신) (0) | 2023.07.14 |
자바(java)/ 가변길이 매개변수 (0) | 2023.07.13 |
자바(java)/ 배열 복사 (0) | 2023.07.13 |
자바(java)/ 기본타입과 참조타입의 null 할당 (0) | 2023.07.13 |