본문 바로가기

인강 보습 (인프런,유데미,패스트캠퍼스)

(50)
제네릭스 (3) - HashSet, HashMap, Iterator Hashset import java.util.HashSet; public class _06_HashSet { public static void main(String[] args) { // 세트 HashSet set = new HashSet(); // 데이터 추가 set.add("삼겹살"); set.add("쌈장"); set.add("음료"); set.add("소금"); set.add("후추"); set.add("삼겹살"); set.add("깻잎"); set.add("상추"); set.add("삼겹살"); System.out.println("총 구매 상품 수 : " + set.size()); // 순회 for (String s : set) { System.out.println(s); } System.out..
제네릭스 (2) - Wrapper 클래스, ArrayList, LinkedList Wrapper 클래스 package chap_09; public class _03_WrapperClass { public static void main(String[] args) { // 래퍼 (Wrapper) 클래스 // int double float char Integer i = 123; // int i = 123; Double d = 1.0; // double d = 1.0; Character c = 'A'; // char c = 'A'; System.out.println(i); System.out.println(d); System.out.println(c); System.out.println("---------------"); System.out.println(i.intValue()); Syste..
제네릭스 - (1) _01_Generics public class _01_Generics { public static void main(String[] args) { // 제네릭스 Integer[] iArray = {1, 2, 3, 4, 5}; Double[] dArray = {1.0, 2.0, 3.0, 4.0, 5.0}; String[] sArray = {"A", "B", "C", "D", "E"}; printIntArray(iArray); printDoubleArray(dArray); printStringArray(sArray); System.out.println("-----------------------"); printAnyArray(iArray); printAnyArray(dArray); printAnyArray(..
추상 클래스와 인터페이스 1. 추상 클래스 _01_AbstractClass import chap_08.camera.Camera; import chap_08.camera.FactoryCam; import chap_08.camera.SpeedCam; public class _01_AbstractClass { public static void main(String[] args) { // 데이터 추상화 (Data Abstraction) : 꼭 필요한 부분만 남기고 숨기는 것 // abstract // 추상 클래스 (아직 완성되지 않은 클래스) : 모호해서 객체로 만들 수 없음 // 추상 메소드 (추상 클래스에서만 사용 가능한, 껍데기만 있는 메소드) // Camera camera = new Camera(); FactoryCam fact..
클래스 (3) - 메소드 오버라이딩, 다형성, Super, 참조, Final, 열거형 1. 메소드 오버라이딩 import chap_07.camera.Camera; import chap_07.camera.FactoryCam; import chap_07.camera.SpeedCam; public class _13_MethodOverriding { public static void main(String[] args) { // 메소드 오버라이딩 : 자식 클래스에서 부모 클래스의 메소드를 덮어쓰기 (재정의) Camera camera = new Camera(); FactoryCam factoryCam = new FactoryCam(); SpeedCam speedCam = new SpeedCam(); camera.showMainFeature(); factoryCam.showMainFeature(); ..
클래스 (2) - This, 생성자, Getter&Setter, 접근제어자, 패키지, 상속 1. This _07_This public class _07_This { public static void main(String[] args) { BlackBox b1 = new BlackBox(); b1.modelName = "까망이"; // 까망이(최신형) b1.appendModelName("(최신형)"); System.out.println(b1.modelName); } } BlackBox void appendModelName(String modelName) { this.modelName += modelName; } *객체의 이름이 파라미터와 똑같을 때 this를 써서 파라미터를 호출 2. 생성자 _08_Constuctor public class _08_Constructor { public stati..
클래스 (1) - 클래스, 인스턴스 변수, 클래스 변수, 메소드, 메소드 오버로딩, 클래스 메소드 1. 클래스 객체 지향 프로그래밍 (OOP)란 유지보수가 용이. 높은 재사용성. 예) camera._01_Class // 차량용 블랙박스 // 모델명, 해상도, 가격, 색상 // 우리가 만든 첫 번째 제품 String modelName = "까망이"; String resolution = "FHD"; int price = 200000; String color = "블랙"; // 새로운 제품을 개발 String modelName2 = "하양이"; String resolution2 = "UHD"; int price2 = 300000; String color2 = "화이트"; // 또다른 제품을 개발? BlackBox bbox = new BlackBox(); // BlackBox 클래스로부터 bbox 객체 생성..
메소드 (2) - Overloading, WhenToUse, VariableScope, MainMethod public class _05_Overloading { public static int getPower(int number) { int result = number * number; return result; // return number * number; } public static int getPower(String strNumber) { int number = Integer.parseInt(strNumber); return number * number; } public static int getPower(int number, int exponent) { int result = 1; for (int i = 0; i < exponent; i++) { result *= number; } return re..