Java

์บก์ํ
Encapsulation ( ์บก์ํ ) ์ ํ์ ์ ํ์ (modifier) ํด๋์ค, ๋ณ์, ๋ฉ์๋ ์ ์ธ๋ถ์ ํจ๊ผ ์ฌ์ฉ๋์ด ๋ถ๊ฐ์ ์ธ ์๋ฏธ๋ฅผ ๋ถ์ฌ ์ ๊ทผ ์ ํ์ : private, default(package), protected, public static : ํด๋์ค ๋ ๋ฒจ์ ์์ ์ค์ final : ์์๋ฅผ ๋์ด์ ์์ ํ ์ ์๊ฒ ํจ abstract: ์ถ์ ๋ฉ์๋ ๋ฐ ์ถ์ ํด๋์ค ์์ฑ synchronized: ๋ฉํฐ ์ค๋ ๋์์์ ๋๊ธฐํ ์ฒ๋ฆฌ ์ ๊ทผ ์ ํ์ public class Parent{ public int publicVar;protected int protectedVar;int defaultVar;private int privVar; public void useMember(){ this.publicVar=10;..
๋คํ์ฑ
Polymorphism ์ ์ ๋คํ์ฑ์ด๋ ํ๋์ ๊ฐ์ฒด๊ฐ ๋ง์ ํ(ํ์ )์ ๊ฐ์ง ์ ์๋ ์ฑ์ง์ด๋ค. ๋คํ์ฑ์, ์์๊ด๊ณ์ ์์ ๋ ์กฐ์ํด๋์ค์ ํ์ ์ผ๋ก ์์ ํด๋์ค ๊ฐ์ฒด๋ฅผ ๋ ํผ๋ฐ์ค ํ ์ ์๋ค. ex) ํฅ๋ถ์ด๋นต is a ๋ถ์ด๋นต | ์ํฌ๋ฆผ๋ถ์ด๋นต is a ๋ถ์ด๋นต | ํผ์ ๋ถ์ด๋นต is a ๋ถ์ด๋นต ํ์ฉ ๋คํ์ฑ์ผ๋ก ๋ค๋ฅธ ํ์ ์ ๋ฐ์ดํฐ๋ฅผ ํ๋์ ๋ฐฐ์ด๋ก๊ด๋ฆฌํ ์ ์๋ค public ArrayList(int initialCapacity){ if(initialCapcity>0){this.elementData = new Object [initialCapacity];} else if (initialCapacity ==0 ){this.elementData = EMPTY_ELEMENTDATA;} else{throw new Illeg..

์์
Inheritance (์์) ๐คฆ๐ปโ๏ธ ์์์ ๊ด๊ณ๋ is - a ๊ด๊ณ์ด๋ค ์ ์ ์์์ ๊ธฐ์กด ํด๋์ค์ ์์ฐ (๋งด๋ฒ)๋ฅผ ์์ ํด๋์ค์์ ์ฌ์ฌ์ฉ ํ๊ธฐ ์ํด ์ฐ์ธ๋ค. ํ์ค์์์๋ ๋ฐ๋๋ก, ๋ถ๋ชจ๊ฐ ์์์๊ฒ ์์์์ผ์ฃผ๋ ๊ฒ์ด ์๋๋ผ ์์์ด ๋ถ๋ชจ๋ ํด๋์ค๋ฅผ ์์ํ๋๊ฒ์ด๋ค (๋ถํจ์์) ๊ธฐ์กด ํด๋์ค์ ๋งด๋ฒ๋ฅผ ๋ฌผ๋ ค๋ฐ๊ธฐ ๋๋ฌธ์ ์ฝ๋๋ฅผ ์ ๊ฐํ ์ ์๊ณ ์ ์ง ๋ณด์๊ฐ ํธ๋ฆฌํ๋ค ํค์๋ : extends public class ๋ถ์ด๋นตํ { String product_name; String fillings; int age ; //unit - min void coolDown(); void eaten (); } public class ๋ถ์ด๋นต extends ๋ถ์ด๋นตํ{ boolean isCarp ; void curse() {} } ๐งธ์์..

์ถ์ํ
Abstraction ํด๋์ค๋ ์ถ์ํ์ ์ต์ ๋จ์์ด๋ค ์์ฑ๊ณผ ๊ธฐ๋ฅ์ ์ถ์ํ ํ์ฌ ํด๋์ค๋ก ๋ง๋ค๊ณ , ์ด ํด๋์ค๋ฅผ ๊ตฌ์ฒดํ ํ๋ฉด ํ๋ก๊ทธ๋จ์ ๊ฐ์ฒด๊ฐ ๋๋ค Practice Problem: ์๋ ํด๋์ค๋ค์ ๊ณตํต ๋ถ๋ชจ๋ฅผ ๋ฝ์์ ์์ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์ด ๋ณด์ public class DiselSuv{ private int curX, curY; public void reportPosition(){System.out.printf("ํ์ฌ ์์น: (%d, %d)%n" ,curX, curY );} public void addFuel(){System.out.printf("์ฃผ์ ์์์ ๊ธ์ ");} } public class ElectricCar{ private int curX, curY; public void reportPosition()..

๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ
๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ ํ์ค ์ธ๊ณ ๊ฐ์ฒด, ํด๋์ค, ๊ฐ์ฒด์ ๊ด๊ณ ํ์ค์ ๊ฐ์ฒด๊ฐ ๊ฐ๋ ์์ฑ๊ณผ ๊ธฐ๋ฅ์ ์ถ์ํ ๋์ด ํด๋์ค์ ์ ์๋๊ณ , ํด๋์ค๋ ๊ตฌ์ฒดํ ๋์ด ํ๋ก๊ทธ๋จ์ ๊ฐ์ฒด(instance, object) ๊ฐ ๋๋ค. EX: ๋ถ์ด๋นต ํ == type ๊ท์ ๋ถ์ด๋นต == ๊ฐ์ฒด ์ฆ, ํด๋์ค๋ ๊ฐ์ฒด๋ฅผ ์ ์ํด ๋์ ๊ฐ์ฒด์ ์ค๊ณ๋ or ํ๋ก ์ง์ ์ฌ์ฉํ ์ ์๊ณ ์ง์ ์ฌ์ฉ๋๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ธฐ ์ํ "ํ" ์ ์ ๊ณตํ ๋ฟ์ด๋ค. ๋ฐ๋ฉด**, ๊ฐ์ฒด** (instance, object ) ๋ ํด๋์ค๋ฅผ ๋ฐ์ดํฐ ํ์ ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ์ ์์ฑ๋ ๊ฒ์ด๋ค. /* ๋ถ์ด๋นตํ ํด๋์ค๋ ํ์ผ ๋ฟ, * ์ง์ ์ฌ์ฉํ ์ ์๋ค*/ Public class ๋ถ์ด๋นตํ{ // ๋งด๋ฒ ๋ณ์: String Name, Fillings ; int age; //unit: min // ๋ฉ..

Class Case Exception
Class Case Exception import java.util.Arrays; class Burger{ String name; int price; Burger(String name, int price){} } public class Test01 { public static void main(String[] args) { Burger[] burgers = new Burger[3]; burgers[0] = new Burger("1957",6000); burgers[1] = new Burger("๋๋ธ๋ถ๊ณ ๊ธฐ",7000); burgers[2] = new Burger("ํ์ฐ๋ฒ๊ฑฐ", 8000); Arrays.sort(burgers); //Exception occurs } } ์ ์ฝ๋๋ฅผ ์คํ ์ํค๋ฉด ClassCas..