클래스 선언하기 Declaring Classes
다음과 같이 정의된 클래스가 있습니다:
You've seen classes defined in the following way:
class MyClass {
// 필드(field), 생성자(constructor), 그리고
// 메소드 선언(method declarations)
}
이것이 클래스 선언 입니다.
This is a class declaration.
클래스 몸체(중괄호 사이의 영역)에는, 클래스에서 생성되는 객체들이 살아있는 동안 제공되는 모든 코드 (새 객체들을 초기화하는 생성자들, 클
래스와 그 객체들의 상태를 제공하는 필드, 클래스 및 객체들의 동작을 구현하는 메소드들에 대한 선언)가 포함됩니다.
The class body (the area between the braces) contains all the code that provides for the life cycle of the objects created from the class: constructors for initializing new objects, declarations for the fields that provide the state of the class and its objects, and methods to implement the behavior of the class and its objects.
앞의 클래스 선언은 최소한의 것입니다.
클래스 선언에 클래스 선언의 필수요소들만 포함되어 있습니다.
클래스에 대한 정보를 추가로 제공할 수 있는데, 시작 지점에 수퍼클래스 이름, 클래스의 interfaces 구현 여부 등을 제공할 수 있습니다.
The preceding class declaration is a minimal one. It contains only those components of a class declaration that are required. You can provide more information about the class, such as the name of its superclass, whether it implements any interfaces, and so on, at the start of the class declaration.
예를 들어, For example,
class MyClass extends MySuperClass implements YourInterface { // field, constructor, method 선언 }
MyClass
는 MySuperClass
의 하위클래스임을, 그리고 MyClass
가 인터페이스 YourInterface
를 implement 함을 의미합니다.
means that MyClass
is a subclass of MySuperClass
and that it implements the YourInterface
interface.
또한 맨 앞에 public 또는 private와 같은 제한자를 추가할 수 있는데 — 그러면 클래스 선언의 시작 줄이 아주 복잡해짐을 볼 수 있습니다.
다른 클래스들이 MyClass
에 접근할 수 있는지를 정하는 제한자인 public과 private는 이 단원의 뒤에서 논의됩니다.
인터페이스와 상속(inheritance) 단원에서, 클래스 선언에서 키워드 extends와 implements를 사용하는 방법과 이유를 설명할 것입니다.
잠깐이라도 이러한 복잡한 것에 걱정은 할 필요가 없습니다.
You can also add modifiers like public or private at the very beginning—so you can see that the opening line of a class declaration can become quite complicated. The modifiers public and private, which determine what other classes can access MyClass
, are discussed later in this lesson. The lesson on interfaces and inheritance will explain how and why you would use the extends and implements keywords in a class declaration. For the moment you do not need to worry about these extra complications.
일반적으로, 클래스 선언에는 이들 컴포넌트들이 순서대로 포함될 수 있습니다:
In general, class declarations can include these components, in order:
1. public, private 그리고 나중에 만나게 될 기타 많은 제한자들.
Modifiers such as public, private, and a number of others that you will encounter later.
2. 협약 상 첫글자가 대문자인 클래스 이름
The class name, with the initial letter capitalized by convention.
3. 클래스의 부모(수퍼클래스)의 이름, 있다면, 키워드 extends의 뒤에. 1개의 클래스는 1개의 부모 만을 extend 할 수 있음.
The name of the class's parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
4. 쉼표로 구분되는 클래스가 구현한 인터페이스의 목록, 있다면,키워드 implements의 뒤에, 1개의 클래스는 2개 이상의 인터페이스를 implement 할 수 있습니다.
A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
5. 클래스 몸체는 중괄호 {}로 둘러쌉니다.
The class body, surrounded by braces, {}.
www.dopza.com
돕자몰 - 강아지 고양이 발작 경련 CBD 오일 전문
반려동물 개 고양이 발작 경련 통증 CBD 오일 전문
www.dopza.com
'Java 배우기' 카테고리의 다른 글
Defining Methods 메소드 정의하기 (0) | 2016.01.05 |
---|---|
Declaring Member Variables 멤버변수 선언하기 (0) | 2016.01.05 |
Classes 클래스 (0) | 2016.01.05 |
Lesson: Classes and Objects 단원: 클래스와 객체 (0) | 2016.01.05 |
Questions and Exercises: Control Flow Statements (0) | 2016.01.05 |
댓글