티스토리 뷰

JAVA/PRIMER

자바 생성자

yulrang 2018. 4. 19. 14:00
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
class·L{¬
————public·L(){¬
————————this(1.5);——//···¬
————————System.out.println("·");¬
————}¬
————public·L(int·a){¬
————————this();//·=·L();¬
————————System.out.println(a);¬
————}¬
————//·this()·:······.¬
————public·L(double·a){¬
————————System.out.println(a);¬
————}¬
————¬
————void·print(){¬
————————//this();———//·····¬
————}¬
}¬
public·class·5·{¬
¬
————public·static·void·main(String[]·args)·{¬
————————L·a·=·new·L(1);¬
————————System.out.println();¬
————————L·b·=·new·L();¬
————}¬
¬
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

1.5

기본 생성자

1


1.5

기본 생성자






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
class·Abc{¬
————int·a,b,c;¬
————¬
————public·Abc(int·a,·int·b,·int·c){¬
————————this.a·=·a;¬
————————this.b·=·b;¬
————————this.c·=·c;¬
————————System.out.println(a+b+c);¬
————}¬
————public·Abc(int·a,·int·b){¬
————————this(a,b,0);¬
————}¬
————public·Abc(int·a){¬
————————this(a,0,0);¬
————}¬
————public·Abc(){¬
————————this(0,0,0);¬
————}¬
}¬
public·class·3·{¬
¬
————public·static·void·main(String[]·args)·{¬
————————Abc·a·=·new·Abc(1,2,3);¬
————————Abc·a2·=·new·Abc(1,2);¬
————————Abc·a3·=·new·Abc(1);¬
————————Abc·a4·=·new·Abc();¬
————}¬
¬
}¬
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6
3
1
0


'JAVA > PRIMER' 카테고리의 다른 글

자바 StringTokenizer  (0) 2018.04.19
자바 클래스배열  (0) 2018.04.19
자바 static 변수  (0) 2018.04.19
자바 접근지정자  (0) 2018.04.19
자바 가변길이인수  (0) 2018.04.19
댓글