web -> cloud / MSA
상속 ... extends
super 클래스는 sub 클래스보다 큰 개념이며 공통된 부분을 가지고 있다.
확장성, 재사용성을 고려해서 상속, 설계를 진행
is a .. 점점 구체화 /
has a .. 독립된 걸 필요에 따라 / 관리클래스 메소드 필요.. 재가공
호출 시 생성자가 필요.. 생성자에는 default super() 항상 존재
http://webcache.googleusercontent.com/search?q=cache:ljwYPOSsIhcJ:m.blog.naver.com%2Fdlaxodud2388%2F221958843956&cd=1&hl=ko&ct=clnk&gl=kr
추상클래스 .. 추상메소드 1개 이상 = 강제성 발생
... 자식메소드에게 강제성으로 고유의 기능을 부여하도록 함
... stack que / draw rect, tri
... 단일 상속만 가능 (모호성 방지)
오버라이딩의 목적 : 동적 바인딩 시 부모가 자식에 접근/인식 가능하도록
... 자식이 부모를 사용 시 super.draw
인터페이스 Interface (≠ class)
- 추상클래스를 더 추상화 시킨 개념
- 단일 상속만 가능했던 (추상)클래스의 문제점을 개선하기 위해
- 다중 상속을 대체할 수 있게 사용
- 구성요소
- 상수 = 읽기만 가능
- 추상메소드 = no body, no 기능
- 식당의 메뉴판과 같은 느낌
- 다중 상속이 가능하다.
- interface 이름 { 상수; 추상메소드; }
- extends : 상속 > 같은 성질
- implements : 구현
interface Aa{
int a = 100; // final static 생략되어 있음
void disp1(); // abstaract 생략되어 있음 > interface 라 생략 가능
}
interface Bb{
int a = 100; // final static 생략되어 있음
void disp2(); // abstaract 생략되어 있음 > interface 라 생략 가능
}
public class InterExam implements Aa, Bb{ // 인터페이스 상속
@Override // 추상 메소드 오버라이딩
public void disp1() {
}
@Override // 다중 상속
public void disp2() {
} }
스레드... 상속받아 사용, 인터페이스 구현해서 사용
상속과 super() 의 이해
public class SuperExam extends D {
public static void main(String[] args) {
SuperExam se = new SuperExam(1, 2, 3, 4);
System.out.println(se.getA()); // 1 A 클래스의 getA
System.out.println(se.getB()); // 2 B 클래스의 getB
System.out.println(se.getC()); // 3 C 클래스의 getC
System.out.println(se.getD()); // 4 D 클래스의 getD
}
public SuperExam(int a, int b, int c, int d) {
super(a, b, c, d);
}}
class D extends C {
private int d;
public int getD() {
return d;}
public D(int a, int b, int c, int d) {
super(a, b, c);
this.d=d;}}
class C extends B {
private int c;
public int getC() {
return c }
public C(int a, int b, int c) {
super(a, b);
this.c=c; }}
class B extends A {
private int b;
public int getB() {
return b; }
public B(int a, int b) {
super(a);
this.b=b;}}
class A {
private int a;
public int getA() {
return a;}
public A(int a) {
this.a = a;}}
// 주의 super() 는 가장 앞줄에
// 변수는 private 으로..
제네릭
- Generics : 컬렉션(자료구조)
- 객체들을 저장하는 구조적인 성격을 보강하기위해 제공되는 것
- 컵(객체) > 주스컵(Generics) ... 틀 자체를 정형화 시키는 것 : < >
- 일반타입 X .. 객체 타입만 사용가능
- int > intger
- double > Double
- [접근제어] class 클래스명<유형1, 유형2 --- >
- 미결정 타입 ... 모든 타입 만족 가능
- 객체가 만들어질 때 타입 결정됨
package day05;
// static import -> 클래스명 없이 사용 가능
import static java.lang.System.out;
public class GenricEx1<T> {
T[] v;
public void set(T[] n) {
v = n;
}
public void print() {
for (T s : v) {
out.println(s);
}
}
}
package day05;
public class GenericEx1Main {
public static void main(String[] args) {
GenricEx1<String> t = new GenricEx1<String>();
String[] ss = { "애", "아", "서" };
t.set(ss);
t.print();
// bad way
GenricEx1 t1 = new GenricEx1();
Integer[] a = {1,2,3};
t1.set(a);
t1.print();
}
}
Hash & Tree ... 자료구조 (검색구조) ..
Set interface : 중복 X but 느리다
package day05;
import java.util.*;
import static java.lang.System.out;
public class HashSetEx1 {
public static void main(String[] args) {
String[] str = { "Java", "Beans", "Java", "XML" };
HashSet<String> hs1 = new HashSet<String>();
HashSet<String> hs2 = new HashSet<String>();
for (String n : str) {
if (!hs1.add(n))
hs2.add(n);
}
out.println("hs1 : " + hs1.toString());
hs1.removeAll(hs2);
out.println("hs1 : " + hs1.toString());
out.println("hs2 : " + hs2.toString());
}
}
hs1 : [Java, Beans, XML]
hs1 : [Beans, XML]
hs2 : [Java]
쓰레드 - 동기화 처리 Vector
동기화 처리 X - ArrayList + collection(동기화기능)
package day05;
import java.util.Stack;
import static java.lang.System.out;
public class StackEx1 {
public static void main(String[] args) {
String[] groupA = { "우즈벡", "쿠웨잇", "사우디", "한국" };
Stack<String> stack = new Stack<String>();
for (String n : groupA) {
stack.push(n);
}
while (!stack.isEmpty()) {
out.println(stack.pop());
}
}
}
ArrayList ... 정리
Comparator & sort ... 정렬 기능
'강의정리들 > [2023] FullStack' 카테고리의 다른 글
230101_Wed_2 (0) | 2023.01.11 |
---|---|
230101_Wed_1 (0) | 2023.01.11 |
230109_Mon (0) | 2023.01.09 |
230106_Fri (0) | 2023.01.06 |
230105_Thu (0) | 2023.01.05 |