class Paret {
int a = 5;
int b = 10;
[1] public void aa(){
}
[2] public void bb(){
}
/////////////////////////////////////////////////////
class child extends Parent{
int a = 100;
int c = 50;
//재정의
[3]public void aa(){
sys ~ (a) => 가까운 값 100
this.a => 100
super.a => 5 (부모이름과 내 이름이 동일할 때 구분을 하기위해)
}
[4]public void cc(){
aa(); -> 3
this.aa() -> 3
super.aa() -> 1
}
}
부모안에 있는 것은 this로 접근 가능하다.
sys ~ (b) => 10
this.b => 10 (car예제로 다시보기)
super.b => 10
sys ~ (c) => 50
this.b => 50
super.b => x
cc(); -> 4
this.cc -> 4
super.cc -> x 부모에게는 없고 나에게만 있는 것은 super로 접근할 수 없다.
1)Child ch = new child();
2)Parent p = new child();
( 그림파일로 다시보기 )
📌재정의된 메소드는 부모타입일지라도 자식부분이 호출된다
다운캐스팅
p.aa()
- package
-> 클레스의 유형에 따라 폴더를 분류해주는 것
-> java 문서 맨 첫줄 단 한번 선언.
-> 컴파일 방법이 다르다 javac -d . 디렉토리
- import
-> java.lang 이외의 것들을 사용하려면 import가 필요하다.
-> 자동 import 해주는 단축키 : ctrl + shift + o (이클립스)
- final (변수앞, 메소드 앞, 클래스앞)
-> 앞에 나온다면 .. 거의 뭐가 안된다.
final int i ; //값변경불가 (객체가 생성될 때 다른값을 초기화 가능)
: 생성자를 이용해서 초기화 할 수 있다!!
static final int i ; //값변경불가 (모든 동일한객체 공유한 변수 값)
: 생성자에서 초기화 안된다 !!
-abstract : 추상화 <-------> 구체화
->abstract를 선언하면 body를 달면 안된다.
->
abstract class Animal{
public abstract void sound();
public abstract void eat();
public void fly(){ }
}
new Animal(); // 없다 !!! 생성불가
class Cat extends Animal{ //상속
//abstract모든 메소드를 재정의 한다 !!!
public void
'Web > MSA Full-Stack 과정' 카테고리의 다른 글
Kosta Day16 : 자료구조 (JAVA) (0) | 2022.02.11 |
---|---|
Kosta Day14 : Interface (JAVA 인터페이스) (0) | 2022.02.09 |
Kosta Day12 : 상속 / 다형성 (0) | 2022.02.08 |
Kosta Day11 : 싱글톤 클래스 / MVC 패턴 / Class Diagram (0) | 2022.01.28 |
Kosta Day10 : Constructor 생성자 / Goods 실습 코드 간결하게 만들기 (0) | 2022.01.27 |