
์ธ๊ฐ(Person)์ด๋ผ๋ ํด๋์ค ์์ฑ ์ ์ ํ์ ์ผ๋ก age : getter / setter (๋ช ์ด์ธ์ง?) ์ ์ ํ์ ์ผ๋ก sleep : getter /setter (๋ช ์๊ฐ ์๋์ง?) ์์ ๋ฐ์ ์ง์ฅ์ธ(Worker) ๋ง๋ค๊ธฐ ์ ์ ํ์ ์ผ๋ก work(์ผํ๋ ์๊ฐ) : getter /setter ์์ ๋ฐ์ ํ์(Student) ๋ง๋ค๊ธฐ ์ ์ ํ์ ์ผ๋ก study("์ด์ฌํ", "์ ๋นํ", "๋๋ฉด์") package ์์์ค์ต์์ 0113; public class InheritanceEx1 { public static void main(String[] args) { Worker worker = new Worker(); Student student = new Student(); worker.setAge(30); worke..

์์(Inheritance) ์์ ํด๋์ค๊ฐ ๋ถ๋ชจ ํด๋์ค์ ๊ธฐ๋ฅ์ ๊ทธ๋๋ก ๋ฌผ๋ ค๋ฐ์ ์ ์๋ ๊ธฐ๋ฅ ์๋ ์ฝ๋์ฒ๋ผ ์์์ ์ด์ฉํ๊ธฐ ์ํด์๋ extends ํค์๋๋ฅผ ์ฌ์ฉ ์์์ ์ฅ์ ๊ธฐ์กด์ ์์ฑ๋ ํด๋์ค ์ฌํ์ฉ ์ค๋ณต ์ฝ๋ ์์ฑ ์ํด๋ ๋จ ํด๋์ค ๊ฐ์ ๊ณ์ธต์ ๊ด๊ณ๋ฅผ ๊ตฌ์ฑํจ์ผ๋ก์จ ๋คํ์ฑ ํ ๋๊ฐ ๋จ ์๋ฐ์ ์์ ๋ฐฉ์ ๋ค๋จ๊ณ ์์ ๋ฐ ๊ณ์ธต์ ์์์ ์ง์, ๋ค์ค ์์์ ์ง์X ํ์ง๋ง, interface๋ฅผ ํตํด์ ๋ค์ค ์์๊ณผ ์ ์ฌํ ํํ์ ์์ ๊ธฐ๋ฅ ์ ๊ณต package ์์๊ธฐ๋ณธ0113; public class BasicInheritance { public static void main(String[] args) { HouseDog houseDog = new HouseDog(); houseDog.setName("๋ฐฑํธ"); ..
package ์์ดํจ๋๋ง๋ค๊ธฐ0112; public class IPadProMain { public static void main(String[] args) throws InterruptedException { while(true) { IPadProMake iPad = new IPadProMake("iPad Pro"); if(!iPad.continueOrder()) break; iPad.setScreen(); iPad.setColor(); iPad.setMemory(); iPad.setNetwork(); iPad.setName(); iPad.setSerialNum(); iPad.inProductPad(); iPad.productPad(); } } } package ์์ดํจ๋๋ง๋ค๊ธฐ0112; import jav..

๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ(method overloading) ๊ฐ์ ์ด๋ฆ์ ๋ฉ์๋๋ฅผ ์ค๋ณตํ์ฌ ์ ์ํ๋ ๊ฒ ๋ฌผ๋ก ํ ํด๋์ค ๋ด์ ๊ฐ์ ์ด๋ฆ์ ๋ฉ์๋๋ฅผ ๋ ์ด์ ๊ฐ์ง ์ ์์ผ๋ ๋งค๊ฐ๋ณ์์ ๋ณ์ ๊ฐ์๋ ํ์ ์ ๋ค๋ฅด๊ฒ ํ๋ฉด, ํ๋์ ์ด๋ฆ์ผ๋ก ๋ฉ์๋๋ฅผ ์์ฑํ ์ ์์. ์ด๋ฌํ ๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ์ ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ ํน์ง ์ค ํ๋์ธ '๋คํ์ฑ(polymorphism)'์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ ์ค ํ๋!!! ์ฝ๊ฒ ์ดํดํ๊ธฐ ์ํด... ๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ ๋ํ์ ์ธ ์๋ก println()์ ๋ค ์ ์์. 1. println() 2. println(boolean x) 3. println(char x) 4. println(char[] x) 5. println(double x) 6. println(float x) 7. println(int x) 8...
this ์ฐธ์กฐ ๋ณ์ this ์ฐธ์กฐ ๋ณ์๋ ์ธ์คํด์ค๊ฐ ๋ฐ๋ก ์๊ธฐ ์์ ์ ์ฐธ์กฐํ๋๋ฐ ์ฌ์ฉํ๋ ๋ณ์.. ๋ฐ๋ผ์ this ์ฐธ์กฐ ๋ณ์๋ ํด๋น ์ธ์คํด์ค์ ์ฃผ์๋ฅผ ๊ฐ๋ฆฌํด. * ์์ฑ์์ ๋งค๊ฐ๋ณ์ ์ด๋ฆ๊ณผ ์ธ์คํด์ค ๋ณ์์ ์ด๋ฆ์ด ๊ฐ์ ๋ ์ธ์คํด์ค ๋ณ์ ์์ this.์ ๋ถ์ฌ์ ๊ตฌ๋ถ (this ์๋ถ์ด๋ฉด ์ปดํ์ผ๋ฌ๊ฐ ๊ตฌ๋ถ ๋ชป ํจ) ๋ชจ๋ ์ธ์คํด์ค ๋ฉ์๋์๋ this ์ฐธ์กฐ ๋ณ์๊ฐ ์จ๊ฒจ์ง ์ง์ญ๋ณ์๋ก ์กด์ฌํจ! this() ๋ฉ์๋ - ๋ค๋ฅธ ์์ฑ์ ํธ์ถ ์์ฑ์ ์ค๋ฒ๋ก๋ฉ์ด ๋ง์์ง ๊ฒฝ์ฐ ์์ฑ์ ๊ฐ์ ์ค๋ณต์ฝ๋๊ฐ ๋ฐ์ํ ์ ์์. this() ๋ฉ์๋๋ ์์ฑ์ ๋ด๋ถ์์๋ง ์ฌ์ฉ ๊ฐ๋ฅํ๋ฉฐ, ๊ฐ์ ํด๋์ค์ ๋ค๋ฅธ ์์ฑ์๋ฅผ ํธ์ถํ ๋ ์ฌ์ฉํจ. this() ๋ฉ์๋์ ์ธ์๋ฅผ ์ ๋ฌํ๋ฉด, ์ผ์นํ๋ ์์ฑ์๋ฅผ ์ฐพ์์ ํธ์ถํด ์ค!! class Car { private..
๋ฌธ์ ๊ทน์ฅ์ ์ข์์ ์ด 10๊ฐ ์ข์๋น ๊ฐ๊ฒฉ์ 12,000์ ๋ฉ๋ด๋ [์์ฝํ๊ธฐ], [์ข ๋ฃํ๊ธฐ]๋ก ๊ตฌ์ฑ [์์ฝํ๊ธฐ]๋ฅผ ๋๋ฅด๋ฉด ํ์ฌ ์ข์์ ์์ฝ ์ํ๋ฅผ ๋ณด์ฌ์ฃผ๊ณ ์์ฝ์ ๋ฐ์ [์ข ๋ฃํ๊ธฐ]๋ฅผ ๋๋ฅด๋ฉด ํ๋งค๋ ์ข์์ ๊ฐฏ์๋ฅผ ํ์ธํด์ ํ๋งค ๊ธ์ก์ ์ถ๋ ฅ package ์ํํฐ์ผ์๋งค; import java.util.Scanner; public class TicketMain { public static void main(String[] args) { TicketReservation movie = new TicketReservation(); Scanner sc = new Scanner(System.in); while(true) { System.out.println("[1]์์ฝํ๊ธฐ"); System.out.println("[2]..

package TV๋ง๋ค๊ธฐ; public class TvMain { public static void main(String[] args) { TvInfo samsung = new TvInfo(); samsung.setON(true); samsung.getTV(); samsung.setChannel(); samsung.setVolume(); samsung.getTV(); } } package TV๋ง๋ค๊ธฐ; import java.util.Scanner; public class TvInfo { private boolean isON; private int channel; private int volume; TvInfo(){ isON = false; channel = 7; volume = 15; } TvInfo(bo..
์์ฑ์(constructor) ํด๋์ค๋ฅผ ๊ฐ์ฒด๋ก ๋ง๋ค๋ ์๋์ผ๋ก ํธ์ถ(=new๋ฅผ ํธ์ถํ ๋)๋๋ฉฐ, ์์ฑ์๋ ์ธ์คํด์ค ํ๋๋ฅผ ์ด๊ธฐํ ํจ. ์์ฑ์๋ ์ธ์คํด์ค ํ๋๋ฅผ ์ด๊ธฐํํ๋ ๊ฒ์ด ๋ชฉ์ ์. ์์ฑ์ ์์ฑ ๊ท์น ์์ฑ์๋ ํด๋์ค ์ด๋ฆ๊ณผ ๊ฐ์์ผ ํจ. ๋ฐํํ์ ์๊ณ ์ ๊ทผ์ ํ์๋ง ์ฌ ์ ์์ผ๋ private์ ํน๋ณํ ๊ฒฝ์ฐ๊ฐ ์๋๋ฉด ์ฌ์ฉ ์ ํจ. ํ๋์ ํด๋์ค๋ ์ฌ๋ฌ๊ฐ์ ์์ฑ์๋ฅผ ๊ฐ์ง ์ ์์. ๋จ, ์ค๋ฒ๋ก๋ฉ ์์ฑ ๊ท์น์ ๋ง์์ผ ํจ. ์ค๋ฒ๋ก๋ฉ ๊ท์น ๋ฐ์ดํฐ ํ์ ์ด ๊ฐ์๋ ๊ฐฏ์๊ฐ ๋ค๋ฅด๋ฉด ๊ฐ๋ฅ ๋ฐ์ดํฐ ํ์ ์ด ๊ฐ๊ณ ๊ฐฏ์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ, ๋ณ์๋ช ์ด ๋ฌ๋ผ๋ ์์ฉ์์. ์ค๋ฒ๋ก๋ฉ์ ๋ํด์๋ ๋ฉ์๋์์ ์์ธํ ๋ค๋ฃฐ ์์ package ์์ฑ์๊ธฐ๋ณธ์ฐ์ต0111; public class ConstructorEx { public static void..
PC๋ฐฉ์ ์ปดํจํฐ๊ฐ ์ด 100๋ ์์ต๋๋ค. ์๋๋ค์ ๋ชจ๋ ์๊ธฐ๊ฐ ์๊ณ ์ถ์ดํ๋ ์๋ฆฌ๊ฐ ์์ต๋๋ค. ๋ง์ฝ ์๊ธฐ๊ฐ ์๊ณ ์ถ์ดํ๋ ์๋ฆฌ์ ๋ค๋ฅธ ์๋์ด ์์ผ๋ฉด ๊ฑฐ์ ์ ํด์ผํ๊ณ , ์๋๋ฉด ์๋ฆฌ ์ฌ์ฉ์ ํ๊ฐ ํฉ๋๋ค. ์ ๋ ฅ ์๋์ ์ : 3 ์๋์ด ์๊ณ ์ถ์ด ํ๋ ์๋ฆฌ ๋ฒํธ : 1 1 5 ์ถ๋ ฅ ๊ฑฐ์ ํ์ : 1 package PC๋ฐฉ์๋ฐ๋ฌธ์ ; import java.util.Scanner; public class PcRoom { public static void main(String[] args) { int[] pcRoom = new int[100]; int seat; int cnt = 0; Scanner sc = new Scanner(System.in); System.out.print("์๋ ์ : "); int n = s..
ํด๋์ค ๋ด์ ์์ฑ์๊ฐ ์์ผ๋ฉด ๊ธฐ๋ณธ ์์ฑ์๊ฐ ํธ์ถ๋จ Sample sample = new Sample(); package ๋ฉ์๋์ฐ์ต0110; import java.util.Scanner; public class ClassMethod { public static void main(String[] args) { Sample sample = new Sample(); Scanner sc = new Scanner(System.in); System.out.print("์ ์๊ฐ ์ ๋ ฅ : "); int n1 = sc.nextInt(); System.out.print("์ ์๊ฐ ์ ๋ ฅ : "); int n2 = sc.nextInt(); int rst = sample.sum(n1, n2); // sum()์ ๋งค๊ฐ๋ณ์์ ๋ฐํ๊ฐ์ด ์..