Skip to content

Commit

Permalink
[Week2][Chap9] 상속과 메서드 오버라이딩 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jan 16, 2024
1 parent dc3b931 commit 1696cbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 0 additions & 9 deletions 김아린/java-basic/src/extends1/ex3/CarMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@ public class CarMain {
public static void main(String[] args) {
ElectricCar electricCar = new ElectricCar();
electricCar.move();
electricCar.charge();
electricCar.openDoor();

GasCar gasCar = new GasCar();
gasCar.move();
gasCar.fillUp();
gasCar.openDoor();

HydrogenCar hydrogenCar = new HydrogenCar();
hydrogenCar.move();
hydrogenCar.fillHydrogen();
hydrogenCar.openDoor();
}
}
9 changes: 9 additions & 0 deletions 김아린/java-basic/src/extends1/ex3/ElectricCar.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package extends1.ex3;

public class ElectricCar extends Car {

// Override 애노테이션은 생략해도 되지만, 어떤 표시임
// method가 override를 하지 않았다면 컴파일 오류를 내준다!
// 개발자 입장에서는 실수하지 않을 수 있는 제약을 만들어줌
@Override
public void move() {
System.out.println("전기차를 빠르게 이동합니다.");
}
public void charge() {

System.out.println("충전합니다.");
}
}

0 comments on commit 1696cbb

Please sign in to comment.