final
- 상수지만 초기화하지않고
- 생성자에서 단한번만 초기화 할수있다.
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
32
33
34
35
36
37
38
class Card
{
final int NUMBER;
final String KIND;
static int width = 100;
static int height = 250;
Card(String kind, int num)
{
KIND = kind;
NUMBER = num;
}
Card()
{
this("HEART", 1);
}
public String toString()
{
return KIND +" " + NUMBER;
}
}
public class Sample2 {
public static void main(String[] args) {
// 접근제어자
Card c = new Card("HEART", 10);
//c.NUMBER = 5;
System.out.println(c.KIND);
System.out.println(c.NUMBER);
System.out.println(c); // 내부적으로 toString 메서드호
}
}
여기서 보이는 toString 메소드 많이 사용할것이다.