Notice
Recent Posts
Recent Comments
Β«   2024/11   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
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
Archives
Today
In Total
관리 메뉴

A Joyful AI Research Journey🌳😊

[31] 230210 Java Ch. 6 클래슀: 2. ν•„λ“œ, 3. μƒμ„±μž, 4. λ©”μ„œλ“œ [K-디지털 νŠΈλ ˆμ΄λ‹ 31일] λ³Έλ¬Έ

🌳Bootcamp Revision 2023✨/Spring Framework, Java

[31] 230210 Java Ch. 6 클래슀: 2. ν•„λ“œ, 3. μƒμ„±μž, 4. λ©”μ„œλ“œ [K-디지털 νŠΈλ ˆμ΄λ‹ 31일]

yjyuwisely 2023. 2. 10. 12:50

230210 Fri 31th class

Ch. 6 클래슀
진도: p. 248 ~ (ꡐ재: 혼자 κ³΅λΆ€ν•˜λŠ” μžλ°”, μ €μž: μ‹ μš©κΆŒ)

 

혼자 κ³΅λΆ€ν•˜λŠ” μžλ°” | μ‹ μš©κΆŒ - ꡐ보문고

혼자 κ³΅λΆ€ν•˜λŠ” μžλ°” | 혼자 해도 μΆ©λΆ„ν•˜λ‹€! 1:1 κ³Όμ™Έν•˜λ“― λ°°μš°λŠ” μžλ°” ν”„λ‘œκ·Έλž˜λ° μžμŠ΅μ„œ (JAVA 8 &11 지원) 이 책은 λ…ν•™μœΌλ‘œ μžλ°”λ₯Ό λ°°μš°λŠ” μž…λ¬Έμžκ°€ ‘κΌ­ ν•„μš”ν•œ λ‚΄μš©μ„ μ œλŒ€λ‘œ’ ν•™μŠ΅ν•  수 μžˆλ„

product.kyobobook.co.kr

였늘 배운 것 쀑 κΈ°μ–΅ν•  것을 μ •λ¦¬ν–ˆλ‹€. 


Ch. 6 ν΄λž˜μŠ€

μ±…μ˜ λͺ©μ°¨
06-1 객체 지ν–₯ ν”„λ‘œκ·Έλž˜λ°
06-2 ν•„λ“œ
06-3 μƒμ„±μž
06-4 λ©”μ†Œλ“œ
06-5 μΈμŠ€ν„΄μŠ€ 멀버와 정적 멀버
06-6 νŒ¨ν‚€μ§€μ™€ μ ‘κ·Ό μ œν•œμž

6.2 ν•„λ“œ(Field) p. 224

ν•„λ“œ: κ°μ²΄μ˜ 데이터(멀버 λ³€μˆ˜)κ°€ μ €μž₯λ˜λŠ” κ³³. μƒμ„±μžμ™€ λ©”μ„œλ“œ μ „μ²΄μ—μ„œ μ‚¬μš©λ˜λ©° 객체가 μ†Œλ©Έλ˜μ§€ μ•ŠλŠ” ν•œ 객체와 ν•¨κ»˜ μ‘΄μž¬ν•œλ‹€. 

ν•„λ“œλŠ” 객체의 고유 데이터, 객체가 κ°€μ Έμ•Ό ν•  λΆ€ν’ˆ, 객체의 ν˜„μž¬ μƒνƒœ 데이터λ₯Ό μ €μž₯ν•˜λŠ” 곳이닀.

public class Car{

	//ν•„λ“œ(μ „μ—­λ³€μˆ˜)
    
    //μ•„λž˜λŠ” κΈ°λ³Έ νƒ€μž…μ΄λ‹€.
    //μ œμž‘νšŒμ‚¬(ν˜„λŒ€, μ‚Όμ„±, κΈ°μ•„)
    String company;
    
    //λͺ¨λΈ(SONATA, K5, SM)
    String model;
    
    //색깔(WHITE, BLACK, GRAY)
    String color
    
    //졜고 속도(200)
    int maxSpeed;
    
    //ν˜„μž¬ 속도(60)
    int speed;
    
    //엔진 νšŒμ „ 수(1200RPM)
    int rmp;
    
    //μ•„λž˜λŠ” μ°Έμ‘° νƒ€μž…μ΄λ‹€.
    //λΆ€ν’ˆ
    Body body;
    //엔진
    Engine engine;
    //타이어
    Tire tire;
    
    //μƒμ„±μž
    //λ©”μ„œλ“œ
}

μ°Έκ³ 


6.2.1 ν•„λ“œ μ„ μ–Έ

클래슀 μ€‘κ΄„ν˜Έ {} 블둝 μ–΄λ””μ„œλ“  μ„ μ–Έν•˜λ‚˜, μƒμ„±μžμ™€ λ©”μ„œλ“œ λ‚΄λΆ€μ—μ„œλŠ” μ„ μ–Έν•  수 μ—†λ‹€.
ν•„λ“œ, μ „μ—­λ³€μˆ˜λŠ” μ΄ˆκΈ°κ°’μ„ μ•ˆ 적어도 λœλ‹€. (지역 λ³€μˆ˜λŠ” μ΄ˆκΈ°κ°’ λ„£μ–΄μ•Ό ν•œλ‹€.)

λΆ„λ₯˜ νƒ€μž… μ΄ˆκΈ°κ°’
κΈ°λ³Έ νƒ€μž… μ •μˆ˜ νƒ€μž… byte 0
char \u0000 (빈 곡백)
short 0
int 0
long 0L
μ‹€μˆ˜ νƒ€μž… float 0.0F
double 0.0
논리 νƒ€μž… boolean false
μ°Έμ‘° νƒ€μž… λ°°μ—΄ null
클래슀(String 포함) null
μΈν„°νŽ˜μ΄μŠ€ null

6.2.2 ν•„λ“œ μ‚¬μš©

ν•„λ“œλ₯Ό μ‚¬μš©ν•œλ‹€ = ν•„λ“œκ°’μ„ 읽고 λ³€κ²½ν•˜λŠ” μž‘μ—…
클래슀 λ‚΄λΆ€μ˜ μƒμ„±μžλ‚˜ λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•  경우 λ‹¨μˆœνžˆ ν•„λ“œ μ΄λ¦„μœΌλ‘œ 읽고 λ³€κ²½ν•˜λ©΄ λ˜μ§€λ§Œ,
클래슀 μ™ΈλΆ€μ—μ„œ μ‚¬μš©ν•  κ²½μš°μ—λŠ” μš°μ„ μ μœΌλ‘œ ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό μƒμ„±ν•œ λ’€ ν•„λ“œλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

Car myCar = new Car();

myCar λ³€μˆ˜κ°€ Car 객체λ₯Ό μ°Έμ‘°ν•˜κ²Œ 되면 λ„νŠΈ(.) μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•΄μ„œ speed ν•„λ“œμ— μ ‘κ·Όν•  수 μžˆλ‹€. 
λ„νŠΈ(.) μ—°μ‚°μžλŠ” 개체 μ ‘κ·Ό μ—°μ‚°μžλ‘œ 객체가 가지고 μžˆλŠ” ν•„λ“œλ‚˜ λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜κ³ μž ν•  λ•Œ μ‚¬μš©λœλ‹€. 

예제) Car 클래슀 ν•„λ“œ μ„ μ–Έ Car.java

public class Car {
		//ν•„λ“œ
		//μ œμ‘°νšŒμ‚¬
		String company = "ν˜„λŒ€μžλ™μ°¨";
		//λͺ¨λΈ
		String model = "κ·Έλžœμ €";
		//차의 색깔
		String color = "κ²€μ •";
		//μ΅œλŒ€ 속도값
		int maxSpeed = 350;
		//ν˜„μž¬ 속도 
		int speed; //μœ„μ™€ λ‹€λ₯΄κ²Œ μ΄ˆκΈ°κ°’μ΄ μ—†λ‹€.
	}


μ™ΈλΆ€ ν΄λž˜μŠ€μ—μ„œ Car ν•„λ“œκ°’ 읽기와 λ³€κ²½

//mainλ©”μ„œλ“œκ°€ μžˆλŠ” ν΄λž˜μŠ€μ—μ„œ 객체 생성
public class CarExample {
	public static void main(String[] args) {
		//newλΌλŠ” ν‚€μ›Œλ“œλ‘œ [호좜]ν•œλ‹€. 
		//Carν΄λž˜μŠ€μ—μ„œ μƒμ„±λœ μƒˆλ‘œμš΄ μ£Όμ†Œ(new)λ₯Ό mycarλ³€μˆ˜μ— μ €μž₯ν•œλ‹€.
		//	 	int a = 10
		Car mycar = new Car();
		
		//Carν΄λž˜μŠ€μ— μžˆλŠ” ν•„λ“œκ°’ κ°€μ Έμ˜€κΈ°
		System.out.println("μ œμž‘νšŒμ‚¬ : " + mycar.company);
		System.out.println("λͺ¨λΈλͺ… : " + mycar.company);
		System.out.println("색깔 : " + mycar.company);
		System.out.println("μ΅œκ³ μ†λ„ : " + mycar.company);
		System.out.println("ν˜„μž¬μ†λ„ : " + mycar.company);	
	}
}


예제2) ν•„λ“œ μžλ™ μ΄ˆκΈ°ν™”

public class FieldInitValue {
		//ν•„λ“œ
		byte byteField;//νƒ€μž…μ΄ byteλ©΄, 기본값은 0
		short shortField; //νƒ€μž…μ΄ short이면, 기본값은 0
		int intField; //νƒ€μž…μ΄ int이면, 기본값은 0
		long longField; //νƒ€μž…μ΄ long이면, 기본값은 0
		
		boolean booleanField; //νƒ€μž…μ΄ booleanλ©΄, 기본값은 false 
		char charField; //νƒ€μž…μ΄ char이면, 기본값은 빈 곡백
		
		float floatField; //νƒ€μž…μ΄ floatλ©΄, 기본값은 0.0
		double doubleField; //νƒ€μž…μ΄ double이면, 기본값은 0.0 
		
		int[] arrField; //νƒ€μž…μ΄ λ°°μ—΄νƒ€μž…μ΄λ©΄, 기본값은 null
		String referenceField; //νƒ€μž…μ΄ String이면, 기본값은 null
}

ν•„λ“œκ°’ 좜λ ₯
FieldInitValue fiv new FieldInitValue();

public class FieldInitValueExample {
	public static void main(String[] args) {
		FieldInitValue fiv = new FieldInitValue();
		
		System.out.println("byteField: " + fiv.byteField);
		System.out.println("shortField: " + fiv.shortField);
		System.out.println("intField: " + fiv.intField);
		System.out.println("longField: " + fiv.byteField);
		
		System.out.println("booleanField: " + fiv.booleanField);
		System.out.println("charField: " + fiv.charField);
		
		System.out.println("floatField: " + fiv.floatField);
		System.out.println("doubleField: " + fiv.doubleField);
		
		System.out.println("arrField: " + fiv.arrField);
		System.out.println("referenceField: " + fiv.referenceField);
	}
}

κ²°κ³Ό)

byteField: 0
shortField: 0
intField: 0
longField: 0
booleanField: false
charField: 
floatField: 0.0
doubleField: 0.0
arrField: null
referenceField: null

 

마무리
2가지 ν‚€μ›Œλ“œλ‘œ λλ‚΄λŠ” 핡심 포인트

1) ν•„λ“œ μ„ μ–Έ: ν΄λž˜μŠ€ μ€‘κ΄„ν˜Έ {} 블둝 μ–΄λ””μ„œλ“  μ„ μ–Έν•˜λ‚˜, μƒμ„±μžμ™€ λ©”μ„œλ“œ λ‚΄λΆ€μ—μ„œλŠ” μ„ μ–Έν•  수 μ—†λ‹€.
2) ν•„λ“œ μ‚¬μš©: ν΄λž˜μŠ€ λ‚΄λΆ€μ˜ μƒμ„±μžμ™€ λ©”μ„œλ“œμ—μ„œ λ°”λ‘œ μ‚¬μš©μ΄ κ°€λŠ₯ν•˜λ‚˜, 클래슀 μ™ΈλΆ€μ—μ„œ μ‚¬μš©ν•  κ²½μš°μ—λŠ” λ°˜λ“œμ‹œ 객체λ₯Ό μƒμ„±ν•˜κ³  μ°Έμ‘° λ³€μˆ˜λ₯Ό 톡해 μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

Q2
μ½”λ“œ)

public class Member {
		//이름("μ •μžλ°”")
		String name;
		//아이디("abcd")
		String id;
		//νŒ¨μŠ€μ›Œλ“œ("abcd1234!!")
		String password;
		//λ‚˜μ΄(30)
		int age;
}

Q3
μ½”λ“œ) Member member new Member();

public class MemberExample {
	public static void main(String[] args) {
		//Member 클래슀 객체 생성
		Member member = new Member();
		member.name = "μ΅œν•˜μ–€";//name ν•„λ“œκ°’ λ³€κ²½
		member.age = 23;//age ν•„λ“œκ°’ λ³€κ²½
	}
}

6.3 μƒμ„±μž p. 232

μƒμ„±μž: new ν‚€μ›Œλ“œλ‘œ ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό 생성할 λ•Œ ν˜ΈμΆœλ˜μ–΄ 객체의 μ΄ˆκΈ°ν™”λ₯Ό λ‹΄λ‹Ήν•œλ‹€.
(객체 생성: Car mycar = new Car();)

객체 μ΄ˆκΈ°ν™”: 
ν•„λ“œλ₯Ό μ΄ˆκΈ°ν™”ν•˜κ±°λ‚˜ μƒμ„±μž λ‚΄λΆ€μ—μ„œ ν•„λ“œκ°’μ„ μ΄ˆκΈ°ν™”ν•  수 있으며,
λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•΄μ„œ 객체λ₯Ό μ‚¬μš©ν•˜κΈ° 전에 객체λ₯Ό μ‚¬μš©ν•  μ€€λΉ„λ₯Ό ν•˜λŠ” 것이닀.

μ°Έκ³ 

μžλ°”μ—μ„œλŠ” 객체의 생성과 λ™μ‹œμ— μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ₯Ό μ›ν•˜λŠ” κ°’μœΌλ‘œ μ΄ˆκΈ°ν™”ν•  수 μžˆλŠ” μƒμ„±μž(constructor)λΌλŠ” λ©”μ„œλ“œλ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.
μžλ°”μ—μ„œ μƒμ„±μž(constructor)의 이름은 ν•΄λ‹Ή 클래슀의 이름과 κ°™μ•„μ•Ό ν•©λ‹ˆλ‹€.
즉, Car ν΄λž˜μŠ€μ˜ μƒμ„±μžμ˜ 이름은 Carκ°€ λ©λ‹ˆλ‹€.
 
μ΄λŸ¬ν•œ μƒμ„±μžλŠ” λ‹€μŒκ³Ό 같은 νŠΉμ§•μ„ κ°€μ§‘λ‹ˆλ‹€.
 
1. μƒμ„±μžλŠ” λ°˜ν™˜κ°’μ΄ μ—†μ§€λ§Œ, λ°˜ν™˜ νƒ€μž…μ„ voidν˜•μœΌλ‘œ μ„ μ–Έν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
2. μƒμ„±μžλŠ” μ΄ˆκΈ°ν™”λ₯Ό μœ„ν•œ 데이터λ₯Ό 인수둜 μ „달받을 수 μžˆμŠ΅λ‹ˆλ‹€.
3. 객체λ₯Ό μ΄ˆκΈ°ν™”ν•˜λŠ” 방법이 μ—¬λŸ¬ 개 μ‘΄μž¬ν•  κ²½μš°μ—λŠ” ν•˜λ‚˜μ˜ ν΄λž˜μŠ€κ°€ μ—¬λŸ¬ 개의 μƒμ„±μžλ₯Ό κ°€μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.
    즉, μƒμ„±μžλ„ ν•˜λ‚˜μ˜ λ©”μ„œλ“œμ΄λ―€λ‘œ, λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©μ΄ κ°€λŠ₯ν•˜λ‹€λŠ” μ˜λ―Έμž…λ‹ˆλ‹€.

μ°Έκ³ : http://www.tcpschool.com/java/java_methodConstructor_constructor

μ°Έκ³ 


6.3.1 κΈ°λ³Έ μƒμ„±μž

λͺ¨λ“  ν΄λž˜μŠ€λŠ” μƒμ„±μžκ°€ λ°˜λ“œμ‹œ μ‘΄μž¬ν•˜λ©°, μƒμ„±μžλ₯Ό ν•˜λ‚˜ 이상 κ°€μ§ˆ 수 μžˆλ‹€. 
μš°λ¦¬κ°€ 클래슀 내뢀에 μƒμ„±μž 선언을 μƒλž΅ν–ˆλ‹€λ©΄ 클래슀 μ„ μ–Έ μ‹œ μ»΄νŒŒμΌλŸ¬μ— μ˜ν•΄ μžλ™μœΌλ‘œ μΆ”κ°€λ˜λŠ” μƒμ„±μžμ΄λ‹€. (μƒμ„±μžλ₯Ό μƒλž΅ν•˜λ©΄ κΈ°λ³Έ μƒμ„±μžλ₯Ό μžλ™μœΌλ‘œ μΆ”κ°€ν•œλ‹€.) μ–ΈκΈ‰ μ•ˆ ν•˜λ©΄ κΈ°λ³Έ μƒμ„±μžλ₯Ό μ“΄λ‹€. 

ν΄λž˜μŠ€κ°€ public class둜 μ„ μ–Έλ˜λ©΄ κΈ°λ³Έ μƒμ„±μžμ—μ„œλ„ public이 λΆ™μ§€λ§Œ,
ν΄λž˜μŠ€κ°€ public 없이 class둜만 μ„ μ–Έλ˜λ©΄ κΈ°λ³Έ μƒμ„±μžμ—λ„ public이 뢙지 μ•ŠλŠ”λ‹€. 

ν΄λž˜μŠ€μ— μƒμ„±μžλ₯Ό μ„ μ–Έν•˜μ§€ μ•Šμ•„λ„ new μ—°μ‚°μž 뒀에 κΈ°λ³Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•΄μ„œ 객체λ₯Ό 생성할 수 μžˆλ‹€.

Car myCar = new Car();

Car(): κΈ°λ³Έ μƒμ„±μž

javascript의 경우
ν•¨μˆ˜ μ„ μ–Έ
function add1(){}
function add2(a,b){}

ν•¨μˆ˜ 호좜
add1(); //()μ΄λ‹ˆκΉŒ ()λ₯Ό ν˜ΈμΆœν•œλ‹€.
add2(10,20); //(a,b)μ΄λ‹ˆκΉŒ (10,20)을 ν˜ΈμΆœν•œλ‹€.

6.3.2 μƒμ„±μž μ„ μ–Έ

ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό 생성할 λ•Œ ν˜ΈμΆœλ˜λŠ” μƒμ„±μžλ₯Ό λͺ…μ‹œμ μœΌλ‘œ μ„ μ–Έν•  수 μžˆλ‹€.
μƒμ„±μžλ₯Ό μ„ μ–Έν•˜λ©΄ κΈ°λ³Έ μƒμ„±μžλŠ” μƒμ„±λ˜μ§€ μ•ŠλŠ”λ‹€.

1. ν΄λž˜μŠ€μ΄λ¦„() { ... }                  // λ§€κ°œλ³€μˆ˜κ°€ μ—†λŠ” μƒμ„±μž μ„ μ–Έ
2. ν΄λž˜μŠ€μ΄λ¦„(인수1, 인수2, ...) { ... } // λ§€κ°œλ³€μˆ˜κ°€ μžˆλŠ” μƒμ„±μž μ„ μ–Έ
public class Car {
		//κΈ°λ³Έ μƒμ„±μž
		//[public] 클래슀λͺ…(){}
		//Car(){}
		
		//κΈ°λ³Έ μƒμ„±μžκ°€ μ•„λ‹Œ μƒμ„±μžλ₯Ό μ„ μ–Έ
		//클래슀λͺ…(νƒ€μž… λ§€κ°œλ³€μˆ˜λͺ…, νƒ€μž… λ§€κ°œλ³€μˆ˜λͺ… ...){}
		Car(String color, int cc){	
		}		
}
public class CarExample {
	public static void main(String[] args) {
		//newλΌλŠ” ν‚€μ›Œλ“œλ‘œ [호좜]ν•œλ‹€. 
		//Carν΄λž˜μŠ€μ—μ„œ μƒμ„±λœ μƒˆλ‘œμš΄ μ£Όμ†Œ(new)λ₯Ό mycarλ³€μˆ˜μ— μ €μž₯ν•œλ‹€.
		//	 	int a = 10
		Car mycar = new Car("κ²€μ •",3000);
		//Car mycar = new Car();(x): κΈ°λ³Έ μƒμ„±μž X
	}
}

6.3.3 ν•„λ“œ μ΄ˆκΈ°ν™” p. 235

ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체가 생성될 λ•Œ ν•„λ“œλŠ” κΈ°λ³Έ μ΄ˆκΈ°κ°’μœΌλ‘œ μžλ™ μ„€μ •λœλ‹€.
λ§Œμ•½ λ‹€λ₯Έ κ°’μœΌλ‘œ μ΄ˆκΈ°ν™”ν•˜κ³  μ‹Άλ‹€λ©΄ 1) ν•„λ“œλ₯Ό μ„ μ–Έν•  λ•Œ μ΄ˆκΈ°κ°’μ„ μ£ΌλŠ” 방법과 2) μƒμ„±μžμ—κ²Œ μ΄ˆκΈ°κ°’μ„ μ£ΌλŠ” 방법이 μžˆλ‹€. 1)의 경우 λ™μΌν•œ ν΄λž˜μŠ€λ‘œλΆ€ν„° μƒμ„±λ˜λŠ” 객체듀은 λͺ¨λ‘ 같은 값을 가진닀. 

예제) μƒμ„±μžμ—μ„œ ν•„λ“œ μ΄ˆκΈ°ν™”
'this.ν•„λ“œ'λŠ” thisλΌλŠ” μ°Έμ‘° λ³€μˆ˜λ‘œ ν•„λ“œλ₯Ό μ‚¬μš©ν•˜λŠ” 것과 λ™μΌν•˜λ‹€. 

public class Korean {
	//ν•„λ“œ
	//κ΅­κ°€
	String nation = "λŒ€ν•œλ―Όκ΅­"; //λŒ€ν•œλ―Όκ΅­μœΌλ‘œ nationν•„λ“œμ— μ΄ˆκΈ°ν™”
	//μ΄ˆκΈ°ν™”(x) -> λ§€κ°œλ³€μˆ˜κ°€ μžˆλŠ” μƒμ„±μžμ— μ˜ν•΄μ„œ "λ°•μžλ°”"λΌλŠ” λ¬Έμžμ—΄μ΄ name ν•„λ“œμ— μ΄ˆκΈ°ν™”
	String name; 
	//μ΄ˆκΈ°ν™”(x) -> λ§€κ°œλ³€μˆ˜κ°€ μžˆλŠ” μƒμ„±μžμ— μ˜ν•΄μ„œ "011225-1234567"λΌλŠ” λ¬Έμžμ—΄μ΄ ssn ν•„λ“œμ— μ΄ˆκΈ°ν™”
	String ssn;
	
	//μžλ™ μΆ”κ°€: μ•„λž˜μͺ½μ— λ§€κ°œλ³€μˆ˜κ°€ μžˆλŠ” μƒμ„±μžμ— μ˜ν•΄μ„œ
	//μžλ™ μΆ”κ°€λœ κΈ°λ³Έμƒμ„±μžλŠ” 없어진닀.
	//Korean()
	
	//μƒμ„±μž
	Korean(String name, String ssn){
		this.name = name;
		this.ssn = ssn;
	}
}

6.3.4 μƒμ„±μž μ˜€λ²„λ‘œλ”© (Overloading) p. 238

μ™ΈλΆ€μ—μ„œ μ œκ³΅λ˜λŠ” λ‹€μ–‘ν•œ 데이터듀을 μ΄μš©ν•΄μ„œ 객체λ₯Ό μ΄ˆκΈ°ν™”ν•˜λ €λ©΄ μƒμ„±μžλ„ 닀양화될 ν•„μš”κ°€ μžˆλ‹€.

μ˜€λ²„λ‘œλ”©: λ§€κ°œ λ³€μˆ˜λ₯Ό λ‹¬λ¦¬ν•˜λŠ” μƒμ„±μžλ₯Ό μ—¬λŸ¬ 개 μ„ μ–Έν•˜λŠ” 것을 λ§ν•œλ‹€.

μ˜€λ²„λ‘œλ”©μ˜ 쑰건
- λ©”μ„œλ“œμ˜ 이름이 κ°™λ‹€.
- 맀개 λ³€μˆ˜μ˜ νƒ€μž…μ΄ λ‹€λ₯΄λ‹€.
- 맀개 λ³€μˆ˜μ˜ κ°œμˆ˜κ°€ λ‹€λ₯΄λ‹€. 

μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ 경우)

//λ©”μ„œλ“œ μ„ μ–Έ
//μ •μˆ˜+μ •μˆ˜
int add(int a, int b){
	int result = a + b;
    return result;
}
//μ •μˆ˜+μ‹€μˆ˜
double add2(int a, double b){
	double result = a + b;
    return result;
}
//μ‹€μˆ˜+μ •μˆ˜
double add3(double a, int b){
	double result = a + b;
    return result;
}
//μ‹€μˆ˜+μ‹€μˆ˜
double add4(double a, double b){
	double result = a + b;
    return result;
}
//λ©”μ„œλ“œ 호좜
add1(1,2);
add2(1,2.5);
add3(1.5,2);
add4(1.5,2.5);

μžλ°”μ˜ 경우)

//λ©”μ„œλ“œ 호좜
add(1,2);
add(1,2.5);
add(1.5,2);
add(1.5,2.5);

 

예제) μƒμ„±μžμ˜ μ˜€λ²„λ‘œλ”© p. 239

public class Car {
		//ν•„λ“œ
		//μ œμ‘°νšŒμ‚¬
		String company = "ν˜„λŒ€μžλ™μ°¨";
		//λͺ¨λΈ
		String model; //= "κ·Έλžœμ €";
		//차의 색깔
		String color; //= "κ²€μ •";
		//μ΅œλŒ€ 속도값
		int maxSpeed; //= 350;

		//μƒμ„±μž μ„ μ–Έ
		Car(){//맀개 λ³€μˆ˜κ°€ μ—†λŠ” μƒμ„±μž - κΈ°λ³Έ μƒμ„±μž
			
		}
		
		Car(String model){//맀개 λ³€μˆ˜κ°€ 1개인 μƒμ„±μž
			this.model = model;
		}
		
		Car(String model, String color){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž - 맀개 λ³€μˆ˜λŠ” νƒ€μž…μ΄ κ°™μŒ(String, String)
			this.model = model;
			this.color = color;
		}
		
		Car(String model, int speed){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž - 맀개 λ³€μˆ˜λŠ” νƒ€μž…μ΄ 닀름(String, int)
			this.model = model;
			this.speed = speed;
		}
		
		Car(String model, String color, int maxSpeed){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž
			this.model = model;
			this.color = color;
			this.maxSpeed = maxSpeed;
		}
}

예제) 객체 생성 μ‹œ μƒμ„±μž 선택

public class CarExample {
	public static void main(String[] args) {
		//newλΌλŠ” ν‚€μ›Œλ“œλ‘œ [호좜]ν•œλ‹€. 
		//Carν΄λž˜μŠ€μ—μ„œ μƒμ„±λœ μƒˆλ‘œμš΄ μ£Όμ†Œ(new)λ₯Ό mycarλ³€μˆ˜μ— μ €μž₯ν•œλ‹€.
		//	 	int a = 10
		//Car mycar = new Car("κ²€μ •",3000);
		//Car mycar = new Car();(x): κΈ°λ³Έ μƒμ„±μž X
		
		//Carν΄λž˜μŠ€μ— μžˆλŠ” ν•„λ“œκ°’ κ°€μ Έμ˜€κΈ°
		//System.out.println("μ œμž‘νšŒμ‚¬ : " + mycar.company);
		//System.out.println("λͺ¨λΈλͺ… : " + mycar.company);
		//System.out.println("색깔 : " + mycar.company);
		//System.out.println("μ΅œκ³ μ†λ„ : " + mycar.company);
		//System.out.println("ν˜„μž¬μ†λ„ : " + mycar.company);	
		
		//Carν΄λž˜μŠ€μ—μ„œ μƒμ„±λœ μƒˆλ‘œμš΄ μ£Όμ†Œ(new)λ₯Ό mycarλ³€μˆ˜μ— μ €μž₯ν•œλ‹€.
		//				맀개 λ³€μˆ˜κ°€ μ—†λŠ” μƒμ„±μž 호좜 - κΈ°λ³Έ μƒμ„±μž 호좜
		Car car1 = new Car();
		System.out.println(car1.company);
		System.out.println();
		
		Car car2 = new Car("μžκ°€μš©");
		System.out.println(car2.company);
		System.out.println(car2.model);
		System.out.println();
		
		Car car3 = new Car("μžκ°€μš©", "λΉ¨κ°•");
		System.out.println(car3.company);
		System.out.println(car3.model);
		System.out.println(car3.color);
		System.out.println();
		
		Car car31 = new Car("μžκ°€μš©", 200);
		System.out.println(car31.company);
		System.out.println(car31.model);
		System.out.println(car31.speed);
		
		Car car4 = new Car("μžκ°€μš©", "λΉ¨κ°•", 200);
		System.out.println(car4.company);
		System.out.println(car4.model);
		System.out.println(car3.color);
		System.out.println(car4.maxSpeed);
	}
}

6.3.5 λ‹€λ₯Έ μƒμ„±μž 호좜: this() p. 241

this = λ‚˜
this(): κ°μ²΄ μžμ‹ μ˜ 또 λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•  λ•Œ μ‚¬μš©ν•œλ‹€. 

μƒμ„±μž μ˜€λ²„λ‘œλ”©μ΄ λ§Žμ•„μ§ˆ 경우 μƒμ„±μž κ°„μ˜ μ€‘λ³΅λœ μ½”λ“œκ°€ λ°œμƒν•  수 μžˆλ‹€. 이 경우 ν•„λ“œ μ΄ˆκΈ°ν™” λ‚΄μš©μ€ ν•œ μƒμ„±μžμ—κ²Œλ§Œ μ§‘μ€‘μ μœΌλ‘œ μž‘μ„±ν•˜κ³  λ‚˜λ¨Έμ§€ μƒμ„±μžλŠ” μ΄ˆκΈ°ν™” λ‚΄μš©μ„ 가지고 μžˆλŠ” μƒμ„±μžλ₯Ό ν˜ΈμΆœν•˜λŠ” λ°©λ²•μœΌλ‘œ κ°œμ„ ν•  수 μžˆλ‹€.

this()λŠ” μžμ‹ μ΄ λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•˜λŠ” μ½”λ“œλ‘œ λ°˜λ“œμ‹œ μƒμ„±μžμ˜ 첫 μ€„μ—μ„œλ§Œ ν—ˆμš©λœλ‹€. this() λ‹€μŒμ—λŠ” 좔가적인 싀행문듀이 올 수 μžˆλ‹€. 

this() λ©”μ„œλ“œλŠ” μƒμ„±μž λ‚΄λΆ€μ—μ„œλ§Œ μ‚¬μš©ν•  수 있으며, 같은 클래슀의 λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•  λ•Œ μ‚¬μš©ν•©λ‹ˆλ‹€.
this() λ©”μ„œλ“œμ— 인수λ₯Ό μ „λ‹¬ν•˜λ©΄, μƒμ„±μž μ€‘μ—μ„œ λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜(λ©”μ„œλ“œ 이름과 λ§€κ°œλ³€μˆ˜ 리슀트의 μ‘°ν•©)κ°€ μΌμΉ˜ν•˜λŠ” λ‹€λ₯Έ μƒμ„±μžλ₯Ό μ°Ύμ•„ ν˜ΈμΆœν•΄ μ€λ‹ˆλ‹€.

예제 1) λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•΄μ„œ 쀑볡 μ½”λ“œ 쀄이기 

public class Car {
		//ν•„λ“œ
		//μ œμ‘°νšŒμ‚¬
		String company = "ν˜„λŒ€μžλ™μ°¨";
		//λͺ¨λΈ
		String model; //= "κ·Έλžœμ €";
		//차의 색깔
		String color; //= "κ²€μ •";
		//μ΅œλŒ€ 속도값
		int maxSpeed; //= 350;
		//ν˜„μž¬ 속도 
		int speed; //μœ„μ™€ λ‹€λ₯΄κ²Œ μ΄ˆκΈ°κ°’μ΄ μ—†λ‹€.
		
		//μƒμ„±μž μ„ μ–Έ
		Car(){//맀개 λ³€μˆ˜κ°€ μ—†λŠ” μƒμ„±μž - κΈ°λ³Έ μƒμ„±μž
			
		}
		
		Car(String model){//맀개 λ³€μˆ˜κ°€ 1개인 μƒμ„±μž
			//this.model = model;
			this(model,"은색",250);
		}
		
		Car(String model, String color){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž - 맀개 λ³€μˆ˜λŠ” νƒ€μž…μ΄ κ°™μŒ(String, String)
			this.model = model;
			this.color = color;
		}
		
		Car(String model, int speed){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž - 맀개 λ³€μˆ˜λŠ” νƒ€μž…μ΄ 닀름(String, int)
			this.model = model;
			this.speed = speed;
		}
		
		Car(String model, String color, int maxSpeed){//맀개 λ³€μˆ˜κ°€ 2개인 μƒμ„±μž
			this.model = model;
			this.color = color;
			this.maxSpeed = maxSpeed;
		}
}

마무리 
6가지 ν‚€μ›Œλ“œλ‘œ λλ‚΄λŠ” 핡심 포인트
1) κΈ°λ³Έ μƒμ„±μž: 
클래슀 μ„ μ–Έ μ‹œ μ»΄νŒŒμΌλŸ¬μ— μ˜ν•΄ μžλ™μœΌλ‘œ μΆ”κ°€λ˜λŠ” μƒμ„±μžμ΄λ‹€.


2) μƒμ„±μž μ„ μ–Έ: ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό 생성할 λ•Œ ν˜ΈμΆœλ˜λŠ” μƒμ„±μžλ₯Ό λͺ…μ‹œμ μœΌλ‘œ μ„ μ–Έν•  수 μžˆλ‹€.
μƒμ„±μžλ₯Ό μ„ μ–Έν•˜λ©΄ κΈ°λ³Έ μƒμ„±μžλŠ” μƒμ„±λ˜μ§€ μ•ŠλŠ”λ‹€.

3) 맀개 λ³€μˆ˜:
 μƒμ„±μž 호좜 μ‹œ 값을 전달받기 μœ„ν•΄ μ„ μ–Έλ˜λŠ” λ³€μˆ˜λ₯Ό λ§ν•œλ‹€.


4) 객체 μ΄ˆκΈ°ν™”:
 κ°μ²΄λ₯Ό μ‚¬μš©ν•˜κΈ° 전에 μ€€λΉ„ν•˜λŠ” κ³Όμ •μœΌλ‘œ

ν•„λ“œλ₯Ό μ„ μ–Έν•  λ•Œ μ΄ˆκΈ°ν™”ν•˜κ±°λ‚˜ μƒμ„±μž λ‚΄λΆ€μ—μ„œ ν•„λ“œκ°’μ„ μ΄ˆκΈ°ν™”ν•  수 있으며,
λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λŠ” λ‚΄μš©μœΌλ‘œ κ΅¬μ„±λœλ‹€. 

5) μ˜€λ²„λ‘œλ”©:
 λ§€κ°œ λ³€μˆ˜λ₯Ό λ‹¬λ¦¬ν•˜λŠ” μƒμ„±μžλ₯Ό μ—¬λŸ¬ 개 μ„ μ–Έν•˜λŠ” 것을 λ§ν•œλ‹€.


6) this(): κ°μ²΄ μžμ‹ μ˜ 또 λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•  λ•Œ μ‚¬μš©ν•œλ‹€. 



6.4 λ©”μ„œλ“œ p. 247

     λ©”μ„œλ“œλŠ” 객체의 λ™μž‘μ— ν•΄λ‹Ήν•˜λŠ” μ€‘κ΄„ν˜Έ {} 블둝이닀. μ€‘κ΄„ν˜Έ 블둝 이름이 λ©”μ„œλ“œ 이름이며, λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λ©΄ μ€‘κ΄„ν˜Έ 블둝에 μžˆλŠ” λͺ¨λ“  μ½”λ“œλ“€μ΄ μΌκ΄„μ μœΌλ‘œ μ‹€ν–‰λœλ‹€. 


6.4.1 λ©”μ„œλ“œ μ„ μ–Έ

λ©”μ„œλ“œ 선언은 선언뢀와 μ‹€ν–‰ λΈ”λ‘μœΌλ‘œ κ΅¬μ„±λœλ‹€. 

λ¦¬ν„΄νƒ€μž… λ©”μ„œλ“œ 이름 ([λ§€κ°œλ³€μˆ˜μ„ μ–Έ, ...]_{

	μ‹€ν–‰ν•  μ½”λ“œλ₯Ό μž‘μ„±ν•˜λŠ” κ³³ //λ©”μ„œλ“œ μ‹€ν–‰ 블둝
    
}

λ©”μ„œλ“œ μ„ μ–ΈλΆ€ (method signature): λ¦¬ν„΄ νƒ€μž…, λ©”μ„œλ“œ 이름, 맀개 λ³€μˆ˜ μ„ μ–Έ
     - λ¦¬ν„΄ νƒ€μž…: λ©”μ„œλ“œκ°€ λ¦¬ν„΄ν•˜λŠ” κ²°κ³Ό νƒ€μž… ν‘œμ‹œ
     - λ©”μ„œλ“œ 이름
     - λ§€κ°œλ³€μˆ˜μ„ μ–Έ: λ©”μ„œλ“œκ°€ μ‹€ν–‰ν•  λ•Œ ν•„μš”ν•œ 데이터λ₯Ό λ°›κΈ° μœ„ν•œ λ³€μˆ˜
λ©”μ„œλ“œ μ‹€ν–‰ 블둝: μ‹€ν–‰ν•  μ½”λ“œλ₯Ό μž‘μ„±ν•œλ‹€.

μ˜ˆμ‹œ)

public class Calculator {
	//ν•„λ“œ
	
	//μƒμ„±μž
	
	//λ©”μ„œλ“œ
	void powerOn() {
		System.out.println("전원을 μΌ­λ‹ˆλ‹€.");
	}
	
	int plus(int x, int y) {
		int result = x + y;
		return result;
	}
	
	double divide(int x, int y) {
		double result = (double)x / (double)y;
		return result;
	}
	
	void powerOff() {
		System.out.println("전원을 λ•λ‹ˆλ‹€.");
	}
}

1) 리턴 νƒ€μž…

리턴 νƒ€μž… = λ¦¬ν„΄κ°’μ˜ νƒ€μž…
리턴값 = λ©”μ„œλ“œλ₯Ό μ‹€ν–‰ν•œ ν›„μ˜ 결괏값 

λ©”μ„œλ“œμ˜ 리턴값이 μžˆμ„ 경우 리턴 νƒ€μž…μ΄ 선언뢀에 λͺ…μ‹œλ˜μ–΄μ•Ό ν•œλ‹€.
리턴값이 μžˆλŠλƒ μ—†λŠλƒμ— 따라 λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λŠ” 방법이 λ‹€λ₯΄λ‹€.

powerOn(); // 리턴값이 μ—†κΈ° λ•Œλ¬Έμ— λ³€μˆ˜μ— μ €μž₯ν•  λ‚΄μš©μ΄ μ—†λ‹€. 
double result = divide(10, 20); //리턴값을 λ°›κΈ° μœ„ν•΄ 리턴 νƒ€μž…μΈ double νƒ€μž…μœΌλ‘œ μ„ μ–Έλ˜μ–΄μ•Ό ν•œλ‹€.
int result = divide(10, 20); //컴파일 μ—λŸ¬

리턴값을 λ°›κΈ° μœ„ν•΄ 리턴 νƒ€μž…μΈ double νƒ€μž…μœΌλ‘œ μ„ μ–Έλ˜μ–΄μ•Ό ν•œλ‹€.
λ§Œμ•½ result λ³€μˆ˜λ₯Ό int νƒ€μž…μœΌλ‘œ μ„ μ–Έν•˜κ²Œ 되면 double 값을 μ €μž₯ν•  수 μ—†κΈ° λ•Œλ¬Έμ— 컴파일 μ—λŸ¬κ°€ λ°œμƒν•œλ‹€.

리턴값이 μ€‘μš”ν•˜μ§€ μ•Šκ³  λ©”μ„œλ“œ 싀행이 μ€‘μš”ν•  경우 λ³€μˆ˜λ₯Ό μ„ μ–Έν•˜μ§€ μ•Šκ³  λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•  μˆ˜λ„ μžˆλ‹€. 

divide(10, 20);

2) λ©”μ„œλ“œ 이름

- 숫자둜 μ‹œμž‘ν•˜λ©΄ μ•ˆ 되고, $, _λ₯Ό μ œμ™Έν•œ 특수 문자 μ‚¬μš© X
- κ΄€λ‘€μ μœΌλ‘œ λ©”μ„œλ“œ 이름은 μ†Œλ¬Έμžλ‘œ μž‘μ„±ν•œλ‹€.
- μ„œλ‘œ λ‹€λ₯Έ 단어가 ν˜Όν•©λœ 이름이라면 뒀이어 μ˜€λŠ” λ‹¨μ–΄μ˜ 첫 κΈ€μžλŠ” λŒ€λ¬Έμžλ‘œ μž‘μ„±ν•œλ‹€.

잘 μž‘μ„±λœ λ©”μ„œλ“œ μ΄λ¦„μ˜ μ˜ˆμ‹œ (λ©”μ„œλ“œκ°€ μ–΄λ–€ κΈ°λŠ₯을 μˆ˜ν–‰ν•˜λŠ”μ§€ μ‰½κ²Œ μ•Œ 수 μžˆλ‹€. :))

void run(){...}
void startEngine(){...}
String getName(){...}
int[] getScores(){...}

3) 맀개 λ³€μˆ˜ μ„ μ–Έ p. 250

맀개 λ³€μˆ˜λŠ” λ©”μ„œλ“œκ°€ μ‹€ν–‰ν•  λ•Œ ν•„μš”ν•œ 데이터λ₯Ό μ™ΈλΆ€λ‘œλΆ€ν„° λ°›κΈ° μœ„ν•΄ μ‚¬μš©λœλ‹€.
맀개 λ³€μˆ˜κ°€ ν•„μš”ν•œ κ²½μš°λ„ 있고, ν•„μš” μ—†λŠ” κ²½μš°κ°€ μžˆλ‹€.
λ§€κ°œκ°’μ€ λ°˜λ“œμ‹œ 맀개 λ³€μˆ˜μ˜ νƒ€μž…μ— λΆ€ν•©λ˜λŠ” 값이어야 ν•œλ‹€. 

void: λ¦¬ν„΄κ°’이 μ—†λŠ” λ©”μ„œλ“œλŠ” 리턴 νƒ€μž…μœΌλ‘œ voidλ₯Ό κΈ°μˆ ν•΄μ•Ό ν•œλ‹€.
예제) λ©”μ„œλ“œ μ„ μ–Έ 

public class Calculator {
	//ν•„λ“œ
	
	//μƒμ„±μž
	
	//λ©”μ„œλ“œ
	void powerOn() {
		System.out.println("전원을 μΌ­λ‹ˆλ‹€.");
	}
	
	int plus(int x, int y) {
		int result = x + y;
		return result;
	}
	
	double divide(int x, int y) {
		double result = (double)x / (double)y;
		return result;
	}
	
	void powerOff() {
		System.out.println("전원을 λ•λ‹ˆλ‹€.");
	}
}

예제) λ©”μ„œλ“œ 호좜

public class CalculatorExample {
	public static void main(String[] args) {
		Calculator myCalc = new Calculator();
		//Calculator 클래슀의 powerOn λ©”μ„œλ“œ 호좜
		myCalc.powerOn();
		
		//Calculator 클래슀의 plus λ©”μ„œλ“œ 호좜
		int result1 = myCalc.plus(5, 6);
		System.out.println(result1);
		
		byte x = 10;
		byte y = 4;
		
		//Calculator 클래슀의  divide λ©”μ„œλ“œ 호좜
		double result2 = myCalc.divide(x, y);
		System.out.print(result2);
		
		//Calculator 클래슀의 powerOff λ©”μ„œλ“œ 호좜
		myCalc.powerOff();
	}
}

4) 맀개 λ³€μˆ˜μ˜ 개수λ₯Ό λͺ¨λ₯Ό 경우

ex) μ—¬λŸ¬ 개의 수λ₯Ό λͺ¨λ‘ ν•©μ‚°ν•˜λŠ” λ©”μ„œλ“œλ₯Ό μ„ μ–Έ 

해결책은 맀개 λ³€μˆ˜λ₯Ό λ°°μ—΄ νƒ€μž…μœΌλ‘œ μ„ μ–Έν•˜λŠ” 것이닀.

int sum1(int[] values){}

//sum1() λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•  λ•Œ 배열을 λ„˜κ²¨μ€ŒμœΌλ‘œμ¨ λ°°μ—΄μ˜ ν•­λͺ© 값듀을 λͺ¨λ‘ 전달할 수 μžˆλ‹€.
//λ°°μ—΄μ˜ ν•­λͺ© μˆ˜λŠ” ν˜ΈμΆœν•  λ•Œ κ²°μ •λœλ‹€.
int[] values = {1, 2, 3};
int result = sum1(values);
int result = sum1(new int[] {1, 2, 3, 4, 5});

맀개 λ³€μˆ˜λ₯Ό λ°°μ—΄ νƒ€μž…μœΌλ‘œ μ„ μ–Έν•˜λ©΄ λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜κΈ° 전에 배열을 생성해야 ν•˜λŠ” λΆˆνŽΈν•œ 점이 μžˆλ‹€.
κ·Έλž˜μ„œ 배열을 μƒμ„±ν•˜μ§€ μ•Šκ³  κ°’μ˜ λͺ©λ‘λ§Œ λ„˜κ²¨μ£ΌλŠ” 방법도 μžˆλ‹€.

sum2() λ©”μ„œλ“œμ˜ 맀개 λ³€μˆ˜λ₯Ό ...λ₯Ό μ‚¬μš©ν•΄μ„œ μ„ μ–Έν•˜κ²Œ 되면 λ©”μ„œλ“œ 호좜 μ‹œ λ„˜κ²¨μ€€ κ°’μ˜ μˆ˜μ— 따라 μžλ™μœΌλ‘œ 배열이 μƒμ„±λ˜κ³  λ§€κ°œκ°’μœΌλ‘œ μ‚¬μš©λœλ‹€.

int sum2(int ... values){}

//...둜 μ„ μ–Έλœ 맀개 λ³€μˆ˜μ˜ 값은 λ©”μ†Œλ“œ 호좜 μ‹œ μ‰Όν‘œλ‘œ λ‚˜μ—΄ν•΄μ£Όλ©΄ λœλ‹€.
int result = sum2(1, 2, 3);
int result = sum2(1, 2, 3, 4, 5);

//λ‹€μŒκ³Ό 같이 배열을 직접 λ§€κ°œκ°’μœΌλ‘œ μ‚¬μš©ν•΄λ„ μ’‹λ‹€.
int[] values = {1, 2, 3};
int result = sum2(values);
int result = sum2(new int[]{1, 2, 3, 4, 5});

예제 1) 맀개 λ³€μˆ˜μ˜ 개수λ₯Ό λͺ¨λ₯Ό 경우

λ©”μ„œλ“œμ˜ 싀행문이 μ™„μ „νžˆ μΌμΉ˜ν•œλ‹€. μ„ μ–Έ λ°©λ²•λ§Œ λ‹€λ₯Ό 뿐이지 맀개 λ³€μˆ˜μ˜ νƒ€μž…μ΄ λ°°μ—΄μ΄λ―€λ‘œ 처리 λ‚΄μš©μ΄ κ°™λ‹€.

public class Computer {
	//λ©”μ„œλ“œ μ„ μ–Έ μ‹œ λ§€κ°œλ³€μˆ˜μ˜ 개수λ₯Ό λͺ¨λ₯Ό λ•Œ
	//1. 맀개 λ³€μˆ˜μ— λ°°μ—΄ μ„ μ–Έ
	int sum1(int[] values) {
		int sum = 0;
		for(int i=0; i<values.length; i++) {
			sum += values[i];
		}
		return sum;
	}
	
	//2. ...
	int sum2(int ... values) {
		int sum = 0;
		for(int i=0; i<values.length; i++) {
			sum += values[i];
		}
		return sum;
	}
}

예제 2) 맀개 λ³€μˆ˜μ˜ 개수λ₯Ό λͺ¨λ₯Ό 경우

public class ComputerExample {
	public static void main(String[] args) {
		Computer myCom = new Computer();
		
		int[] values1 = {1, 2, 3};
		int result1 = myCom.sum1(values1);
		System.out.println("result1: "+result1);
		
		int result2 = myCom.sum1(new int[] {1, 2, 3, 4, 5});
		System.out.println("result2: "+result2);
		
		int result3 = myCom.sum2(1, 2, 3);
		System.out.println("result3: "+result3);
		
		int result4 = myCom.sum2(1, 2, 3, 4, 5);
		System.out.println("result4: "+result4);
	}
}

6.4.2 리턴(return)λ¬Έ p. 254

1) 리턴값이 μžˆλŠ” λ©”μ„œλ“œ

return 리턴값;

returnλ¬Έ μ΄ν›„μ˜ 싀행문은 κ²°μ½” μ‹€ν–‰λ˜μ§€ μ•ŠλŠ”λ‹€. 


2) 리턴값이 μ—†λŠ” λ©”μ„œλ“œ: void p. 255

리턴값이 μ—†λŠ” λ©”μ„œλ“œλŠ” 리턴 νƒ€μž…μœΌλ‘œ voidλ₯Ό μ‚¬μš©ν•œλ‹€.
void둜 μ„ μ–Έλœ λ©”μ„œλ“œμ—μ„œλ„ return문을 μ‚¬μš©ν•  수 μžˆλ‹€. 리턴값을 μ§€μ •ν•˜λŠ” 것이 μ•„λ‹ˆλΌ
λ©”μ„œλ“œ 싀행을 κ°•μ œλ‘œ μ’…λ£Œμ‹œν‚€λŠ” 역할이닀.

return;
return (null): null둜 returnν•œλ‹€.
submit을 ν•˜μ§€ λͺ»ν•˜κ³  null을 λ°˜ν™˜ν•œλ‹€. ν•΄λ‹Ή return μ•„λž˜λ₯Ό μ „λΆ€ μ‹€ν–‰ν•˜μ§€ μ•Šκ³  return μ€„μ—μ„œ ν΄λž˜μŠ€λ₯Ό λλ‚΄λ²„λ¦°λ‹€.

return true: submit ν•˜κΈ° μ „에 ν•¨μˆ˜μ—μ„œ μœ νš¨μ„± κ²€μ‚¬λ₯Ό ν•˜κ³  ν†΅κ³Όκ°€ λ˜λ©΄ true(=submit true)둜 λ¦¬ν„΄ν•œλ‹€λŠ” λœ»μ΄λ‹€.

return false: κ°’이 λ“€μ–΄κ°€ μžˆμ§€ μ•ŠμœΌλ©΄ submit을 ν•˜μ§€ μ•Šκ³  fasle둜 λ¦¬ν„΄ν•œλ‹€λŠ” λœ»(return nullκ³Ό μ•„μ£Ό μ‘°κΈˆ μ°¨μ΄κ°€ μžˆλ‹€.)이닀.

μ°Έκ³ : https://diaryofgreen.tistory.com/80

예제 1) return문

public class Car {
	//ν•„λ“œ
	int gas;
	
	//μƒμ„±μž
	
	//λ©”μ„œλ“œ
	void setGas(int gas) {
		this.gas = gas; //리턴값이 μ—†λŠ” λ©”μ„œλ“œλ‘œ λ§€κ°œκ°’μ„ λ°›μ•„μ„œ gas ν•„λ“œκ°’μ„ λ³€κ²½
	}
	
	//리턴값이 boolean인 λ©”μ„œλ“œλ‘œ gasν•„λ“œκ°’μ΄ 0이면 falseλ₯Ό, 0이 μ•„λ‹ˆλ©΄ trueλ₯Ό 리턴
	boolean isLeftGas() {
		if(gas == 0) {
			System.out.println("gasκ°€ μ—†μŠ΅λ‹ˆλ‹€.");
			return false; //falseλ₯Ό 리턴
		}
		System.out.println("gasκ°€ μžˆμŠ΅λ‹ˆλ‹€.");
		return true; //trueλ₯Ό 리턴
	}
	
	//리턴값이 μ—†λŠ” λ©”μ„œλ“œλ‘œ gas ν•„λ“œκ°’μ΄ 0이면 return문으둜 λ©”μ„œλ“œλ₯Ό κ°•μ œμ’…λ£Œ
	void run() {
		while(true) {
			if(gas > 0) {
				System.out.println("λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:" + gas + ")");
				gas -= 1;
			}else {
				System.out.println("멈μΆ₯λ‹ˆλ‹€.(gasμž”λŸ‰:" + gas + ")");
				return;
			}
		}
	}
}



예제 2) return문

public class CarExample {
	public static void main(String[] args) {
		Car myCar = new Car();
		
		//Car의 setGas λ©”μ„œλ“œ 호좜
		myCar.setGas(5); 
		
		//isLeftGasλ©”μ„œλ“œ 호좜
		boolean gasState = myCar.isLeftGas();
		if(gasState){
			System.out.println("μΆœλ°œν•©λ‹ˆλ‹€.");
			myCar.run(); //Car의 run() λ©”μ„œλ“œ 호좜
		}
		
		//Car의 isLeftGas() λ©”μ„œλ“œ 호좜
		if(myCar.isLeftGas()) {
			System.out.println("gasλ₯Ό μ£Όμž…ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.");
		}else {
			System.out.println("gasλ₯Ό μ£Όμž…ν•˜μ„Έμš”.");
		}
	}
}

κ²°κ³Ό) 

gasκ°€ μžˆμŠ΅λ‹ˆλ‹€.
μΆœλ°œν•©λ‹ˆλ‹€.
λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:5)
λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:4)
λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:3)
λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:2)
λ‹¬λ¦½λ‹ˆλ‹€.(gasμž”λŸ‰:1)
멈μΆ₯λ‹ˆλ‹€.(gasμž”λŸ‰:0)
gasκ°€ μ—†μŠ΅λ‹ˆλ‹€.
gasλ₯Ό μ£Όμž…ν•˜μ„Έμš”.

6.4.3 λ©”μ„œλ“œ 호좜 p. 258

λ©”μ„œλ“œλŠ” 클래슀 λ‚΄, μ™ΈλΆ€μ˜ ν˜ΈμΆœμ— μ˜ν•΄ μ‹€ν–‰λœλ‹€.
- 클래슀 λ‚΄λΆ€: λ‹¨μˆœν•œ λ©”μ„œλ“œ μ΄λ¦„μœΌλ‘œ 호좜
- 클래슀 μ™ΈλΆ€: ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό μƒμ„±ν•œ λ’€ μ°Έμ‘° λ³€μˆ˜λ₯Ό μ΄μš©ν•΄μ„œ λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•œλ‹€. (객체가 μ‘΄μž¬ν•΄μ•Ό λ©”μ„œλ“œλ„ μ‘΄μž¬ν•˜λ―€λ‘œ)

//μ™ΈλΆ€
void μ™ΈλΆ€λ©”μ„œλ“œ(){
Car car = new Car();
car.run();
car.stop();
car.sound();
}

1) 객체 λ‚΄λΆ€μ—μ„œ 호좜

λ©”μ„œλ“œλ₯Ό μ‹€ν–‰ν•˜λ €λ©΄ 'λ©”μ„œλ“œ 이름(λ§€κ°œκ°’, ...)' ν˜•νƒœλ‘œ ν˜ΈμΆœν•΄μ•Ό ν•œλ‹€.

예제) 클래슀 λ‚΄λΆ€μ—μ„œ λ©”μ„œλ“œ 호좜

public class Calculator {
	//λ©”μ„œλ“œ μ„ μ–Έ
	//λ¦¬ν„΄νƒ€μž… λ©”μ„œλ“œλͺ…([νƒ€μž… λ§€κ°œλ³€μˆ˜])
	int plus(int x, int y) {
		int result = x + y;
		return result;
	}
	
	double avg(int x, int y) {
		double sum = plus(x, y);//plusλ©”μ„œλ“œ 호좜
		double result = sum / 2;
		return result;
	}
	
	void execute() {
		double result = avg(7, 10);//avgλ©”μ„œλ“œ 호좜
		println("μ‹€ν–‰κ²°κ³Ό: " + result);//printlnλ©”μ„œλ“œ 호좜
	}
	
	void println(String message) {
		System.out.println(message);
	}
}

예제) Calculator의 execute() μ‹€ν–‰

public class CalculatorExample {
	public static void main(String[] args) {
		Calculator myCalc = new Calculator();
		//Calculator 클래슀의 powerOn λ©”μ„œλ“œ 호좜
		myCalc.powerOn();
		
		//Calculator 클래슀의 plus λ©”μ„œλ“œ 호좜
		int result1 = myCalc.plus(5, 6);
		System.out.println(result1);
		
		byte x = 10;
		byte y = 4;
		
		//Calculator 클래슀의  divide λ©”μ„œλ“œ 호좜
		double result2 = myCalc.divide(x, y);
		System.out.print(result2);
		
		//Calculator 클래슀의 powerOff λ©”μ„œλ“œ 호좜
		myCalc.powerOff();
	}
}

2) 객체 μ™ΈλΆ€μ—μ„œ 호좜

μ™ΈλΆ€ ν΄λž˜μŠ€μ—μ„œ λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λ €λ©΄ ν΄λž˜μŠ€λ‘œλΆ€ν„° 객체λ₯Ό 생성해야 ν•œλ‹€.
λ©”μ„œλ“œλŠ” 객체에 μ†Œμ†λœ λ©€λ²„μ΄λ―€λ‘œ 객체가 μ‘΄μž¬ν•˜μ§€ μ•ŠμœΌλ©΄ λ©”μ„œλ“œλ„ μ‘΄μž¬ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ΄λ‹€.

클래슀 μ°Έμ‘° λ³€μˆ˜ = new 클래슀(λ§€κ°œκ°’, ...);

λ„νŠΈ μ—°μ‚°μžλŠ” 객체 μ ‘κ·Ό μ—°μ‚°μžλ‘œ 객체가 가지고 μžˆλŠ” ν•„λ“œλ‚˜ λ©”μ„œλ“œμ— μ ‘κ·Όν•  λ•Œ μ‚¬μš©λœλ‹€.

μ°Έμ‘°λ³€μˆ˜.λ©”μ„œλ“œ(λ§€κ°œκ°’, ...); //리턴값이 μ—†κ±°λ‚˜, μžˆμ–΄λ„ 리턴값을 받지 μ•Šμ„ 경우
νƒ€μž… λ³€μˆ˜ = μ°Έμ‘°λ³€μˆ˜.λ©”μ„œλ“œ(λ§€κ°œκ°’, ...); //리턴값이 있고, 리턴값을 λ°›κ³  싢을 경우

예제 1) 클래슀 μ™ΈλΆ€μ—μ„œ λ©”μ„œλ“œ 호좜

public class Car2 {
	//ν•„λ“œ
	int speed;
	//μƒμ„±μž
	
	//λ©”μ„œλ“œ
	int getSpeed() {
		return speed;
	}
	void keyTurnOn() {
		System.out.println("ν‚€λ₯Ό λŒλ¦½λ‹ˆλ‹€.");
	}
	
	void run() {
		for(int i=0; i<=50; i+=10) {
			speed = i;
			System.out.println("λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: "+speed+"km/h)");
		}
	}	
}

예제 2) 클래슀 μ™ΈλΆ€μ—μ„œ λ©”μ„œλ“œ 호좜

public class Car2Example {
	public static void main(String[] args) {
		//λ©”μ„œλ“œ 호좜
		Car2 myCar = new Car2();
		myCar.keyTurnOn();
		myCar.run();
		int speed = myCar.getSpeed();
		System.out.println("ν˜„μž¬ 속도: "+speed+"km/h");
	}
}

κ²°κ³Ό)

ν‚€λ₯Ό λŒλ¦½λ‹ˆλ‹€.
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 0km/h)
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 10km/h)
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 20km/h)
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 30km/h)
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 40km/h)
λ‹¬λ¦½λ‹ˆλ‹€.(μ‹œμ†: 50km/h)
ν˜„μž¬ 속도: 50km/h

6.4.4 λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”© (Overloading) p. 263

λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©: 클래슀 내에 같은 μ΄λ¦„μ˜ λ©”μ„œλ“œλ₯Ό μ—¬λŸ¬ 개 μ„ μ–Έν•˜λŠ” 것
μ˜€λ²„λ‘œλ”©: 많이 μ‹£λŠ” 것
ν•˜λ‚˜μ˜ λ©”μ„œλ“œ μ΄λ¦„μœΌλ‘œ μ—¬λŸ¬ κΈ°λŠ₯을 λ‹΄λ‹Ήν•œλ‹€.
쑰건: 맀개 λ³€μˆ˜μ˜ νƒ€μž…, 개수, μˆœμ„œ 쀑 ν•˜λ‚˜κ°€ 달라야 ν•œλ‹€. 

λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©μ΄ ν•„μš”ν•œ μ΄μœ λŠ” λ§€κ°œκ°’μ„ λ‹€μ–‘ν•˜κ²Œ λ°›μ•„ μ²˜λ¦¬ν•  수 μžˆλ„λ‘ ν•˜κΈ° μœ„ν•΄μ„œμ΄λ‹€. 

맀개 λ³€μˆ˜ νƒ€μž…μ΄ μΌμΉ˜ν•˜μ§€ μ•Šμ„ 경우 μžλ™ νƒ€μž… λ³€ν™˜μ΄ κ°€λŠ₯ν•œμ§€ κ²€μ‚¬ν•œλ‹€.

맀개 λ³€μˆ˜μ˜ νƒ€μž…, 개수, μˆœμ„œκ°€ λ˜‘κ°™μ„ 경우 맀개 λ³€μˆ˜ 이름이 λ‹€λ₯΄λ‹€κ³  ν•΄μ„œ λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©μ΄λΌκ³  ν•˜μ§€ μ•ŠλŠ”λ‹€. 

λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©μ˜ κ°€μž₯ λŒ€ν‘œμ μΈ μ˜ˆλŠ” System.out.println() λ©”μ„œλ“œμ΄λ‹€. ν˜ΈμΆœν•  λ•Œ 주어진 λ§€κ°œκ°’μ˜ νƒ€μž…μ— λ”°λΌμ„œ λ‹€μŒκ³Ό 같이 μ˜€λ²„λ‘œλ”©λœ println()  λ©”μ„œλ“œ 쀑 ν•˜λ‚˜λ₯Ό ν˜ΈμΆœν•œλ‹€.

void println(){...}
void println(boolean x){...}
void println(char x){...}
void println(char[] x){...}
void println(double x){...}
void println(float x){...}
void println(long x){...}
void println(Object x){...}
void println(String x){...}

 

예제 1) λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©
μ–΄λ–€ λ©”μ„œλ“œκ°€ 호좜될 κ²ƒμΈμ§€λŠ” λ§€κ°œκ°’μ˜ λ³€μˆ˜μ— λ‹¬λ €μžˆλ‹€.

public class Calculator {
	//μ •μ‚¬κ°ν˜•μ˜ 넓이
	double areaRectangle(double width) {
		return width * width;
	}
	
	//μ§μ‚¬κ°ν˜•μ˜ 넓이
	double areaRectangle(double width, double height) {
		return width * height;
	}
	
	//μ›μ˜ 넓이
	double areaRectangle(int r) {
		return r * r * Math.PI;
	}
}

예제 2) λ©”μ„œλ“œ μ˜€λ²„λ‘œλ”©

public class CalculatorExample {
	public static void main(String[] args) {
		Calculator myCalcu = new Calculator();
	//μ •μ‚¬κ°ν˜•μ˜ 넓이 κ΅¬ν•˜κΈ°
	double result1 = myCalcu.areaRectangle(10);
	//μ§μ‚¬κ°ν˜•μ˜ 넓이 κ΅¬ν•˜κΈ°
	double result2 = myCalcu.areaRectangle(10, 20);
	//μ›μ˜ 넓이 κ΅¬ν•˜κΈ°
	double result3 = myCalcu.areaRectangle(10);
	
	//κ²°κ³Ό 좜λ ₯
	System.out.println("μ •μ‚¬κ°ν˜• 넓이=" + result1);
	System.out.println("μ •μ‚¬κ°ν˜• 넓이=" + result2);
	System.out.println("μ›μ˜ 넓이=" + result3);
	}
}

마무리 p. 267
6가지 ν‚€μ›Œλ“œλ‘œ λλ‚΄λŠ” 핡심 포인트
1) μ„ μ–ΈλΆ€:
 λ©”μ„œλ“œ μ„ μ–ΈλΆ€λŠ” 리턴 νƒ€μž…, λ©”μ„œλ“œ 이름, 맀개 λ³€μˆ˜ μ„ μ–Έ 뢀뢄을 λ§ν•œλ‹€. 

2) void: 
리턴값이 μ—†λŠ” λ©”μ„œλ“œλŠ” 리턴 νƒ€μž…μœΌλ‘œ voidλ₯Ό κΈ°μˆ ν•΄μ•Ό ν•œλ‹€. 

3) 맀개 λ³€μˆ˜: 
λ©”μ„œλ“œ 호좜 μ‹œ μ œκ³΅λ˜λŠ” λ§€κ°œκ°’μ€ λ©”μ„œλ“œ μ„ μ–ΈλΆ€μ˜ 맀개 λ³€μˆ˜μ— μ°¨λ‘€λŒ€λ‘œ λŒ€μž…λ˜μ–΄, λ©”μ„œλ“œ 블둝 μ‹€ν–‰ μ‹œ μ΄μš©λœλ‹€. 

4) 리턴문:
 λ©”μ„œλ“œ 선언뢀에 리턴 νƒ€μž…μ΄ μžˆλ‹€λ©΄ 리턴값을 μ§€μ •ν•˜κΈ° μœ„ν•΄ return문이 λ°˜λ“œμ‹œ μžˆμ–΄μ•Ό ν•œλ‹€. 리턴 νƒ€μž…μ΄ void라면 return문은 ν•„μš” μ—†μ§€λ§Œ, λ©”μ„œλ“œ μ‹€ν–‰ μ’…λ£Œλ₯Ό μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

5) 호좜:
 λ©”μ„œλ“œλ₯Ό μ‹€ν–‰ν•˜λ €λ©΄ 'λ©”μ„œλ“œ 이름(λ§€κ°œκ°’, ...)' ν˜•νƒœλ‘œ ν˜ΈμΆœν•΄μ•Ό ν•œλ‹€.

6) μ˜€λ²„λ‘œλ”©: 
클래슀 내에 같은 μ΄λ¦„μ˜ λ©”μ„œλ“œλ₯Ό μ—¬λŸ¬ 개 μ„ μ–Έν•˜λŠ” 것
쑰건은 맀개 λ³€μˆ˜μ˜ νƒ€μž…, 개수, μˆœμ„œ 쀑 ν•˜λ‚˜κ°€ 달라야 ν•œλ‹€. 


Q3 
예제) MemberService.java

public class MemberService {
	//μž‘μ„±
	//MemberService 클래슀
	//login λ©”μ„œλ“œ μ„ μ–Έ
	//id, password 제곡
	boolean login(String id, String password) {
		//id = "hong", password = "12345" true 리턴
		if(id.equals("hong")&&password.equals("12345")) {
			return true;
	}else {	//κ·Έ μ™Έ false 리턴 
		return false;
	}
	}
	//logout λ©”μ„œλ“œ μ„ μ–Έ
		//id 제곡
	void logout(String id) {//"λ‘œκ·Έμ•„μ›ƒ λ˜μ—ˆμŠ΅λ‹ˆλ‹€." 좜λ ₯ 
		System.out.println("λ‘œκ·Έμ•„μ›ƒ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
	}
}

예제) MemberServiceExample.java

public class MemberServiceExample {
	public static void main(String[] args) {
		MemberService memberService = new MemberService();
		boolean result = memberService.login("hong", "12345");
		if(result) {
			System.out.println("둜그인 λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
			memberService.logout("hong");
		}else {
			System.out.println("id λ˜λŠ” passwordκ°€ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.");
		}
	}
}

κ²°κ³Ό)

둜그인 λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
λ‘œκ·Έμ•„μ›ƒ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

Q4) 

예제) Printer.java

public class Printer {
	//μž‘μ„± μœ„μΉ˜
	static void println(int value) {
		System.out.println(value);
	}
	static void println(boolean value) {
		System.out.println(value);
	}
	static void println(double value) {
		System.out.println(value);
	}
	static void println(String value) {
		System.out.println(value);
	}
}

예제) PrinterExample.java

public class PrinterExample {
	public static void main(String[] args) {
		Printer printer = new Printer();
		printer.println(10);
		printer.println(true);
		printer.println(5.7);
		printer.println("홍길동");
	}
}

κ²°κ³Ό)

10
true
5.7
홍길동

728x90
λ°˜μ‘ν˜•
Comments