# 클래스의 정의

> ## 클래스 == 데이터 + 함수

## 클래스의 탄생 과정

1. 변수 : 하나의 데이터를 저장할 수 있는 공간
2. 배열 : 같은 종류의 여러 데이터를 하나로 저장할 수 있는 공간
3. 구조체 : 서로 연관된 여러 데이터(종류 관계 X) 를 하나로 저장할 수 있는 공간
4. 클래스 : 데이터와 함수의 결합(구조체 + 함수)

## 클래스 == 사용자 정의 타입

> ### 원하는 타입을 직접 만들 수 있습니다.

### 시간을 다루는 타입을 직접 만들고 싶다면?

* 기본형 8개가 아닌 새로운 타입인 시간 클래스를 작성한다.

> #### 사용자 3명의 시간을 기록하려고 한다.&#x20;

* 클래스 사용을 하지 않고 관리해 보기!

{% code lineNumbers="true" %}

```java
class NoneClassTime {
    public static void main(String[] args) {
        // 총 3명 의 시간을 변수로 관리
        int hour1, hour2, hour3;
        int minute1, minute2, minute3;
        int second1, second2, second3;

        // 총 3명 의 시간을 배열로 관리
        int[] hour = new int[3];
        int[] minute = new int[3];
        int[] second = new int[3];
    }
}
```

{% endcode %}

* 클래스로 만들어서 관리해 보기!

{% code lineNumbers="true" %}

```java
class Time3_1 {
    int hour;
    int minute;
    int second;
}
class Time3_1Main {
    public static void main(String[] args) {
        // 총 3명 의 시간을 객체로 관리
        Time3_1 t1 = new Time3_1();
        Time3_1 t2 = new Time3_1();
        Time3_1 t3 = new Time3_1();

        // 총 3명 의 시간을 객체 배열로 관리
        Time3_1[] timeArr = new Time3_1[3];
        timeArr[0] = new Time3_1();
        timeArr[1] = new Time3_1();
        timeArr[2] = new Time3_1();
    }
}
```

{% endcode %}

{% hint style="info" %}
Ref. Java의 정석 기초편 Chapter6(9, 10)

Ref. [클래스 정의](https://www.youtube.com/watch?v=ML4CO32-bts\&list=PLW2UjW795-f6xWA2_MUhEVgPauhGl3xIp\&index=56)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nbcamp.gitbook.io/java-handbook/part-05./undefined-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
