java 프로그래밍

제 10장 클래스 선언 규칙/ new 연산자

jeongho son 2019. 3. 27. 21:07

 

 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
클래스 선언 규칙!
 
1)하나 이상의 문자로 이루어 져야 한다 Ex) Car, maxSpeed
 
2)첫번째 글자에는 숫자가 올수 없다 Ex) Car(o), 3Car(x)
 
3)'$','_'이외의 특수문자는 사용할수 없다 Ex)$Car(o),_Money(o), ^Go(x), *Color(x)
 
4)자바 키워드는 쓸수 없다 Ex) int(x), for(x)
 
 
 
 
 
new 연산자란??
 
new 연산자란 클래스 선언후 컴파일을 했다면 객체를 생성할 설계도가 
 
만들어 지게 된는데 이때 클래스로부터 객체를 생성할때 쓰는게 new 연산자 입니다
 
 
 
 
 
new 클래스();//클래스()에 생성자를 호출하는 코드를 넣습니다
 
 
 
예를들면 
 
클래스 변수 = new 클래스();// 예를들면 Students s1 = new Students();
 
 
 
 
 
Ex)
 
 
 
public class Student {
 
}
 
 
 
 
 
 
 
  package son;
 
 
 
public class StudentE {
 
 
 
    public static void main(String[] args) {
 
        Student s1 = new Student();
 
        
 
        System.out.println("s1 변수 Student 객체를 참고합니");
 
        
 
        
 
        Student s2 = new Student();
 
        System.out.println("s2 변수 또다른 Student 객체를 참고합니");
 
        
 
 
 
    }
 
 
 
}
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs