Skip to content

Commit

Permalink
[Week1][입문편] 3강 코틀린에서 상속을 다루는 방법 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjsmk0902 committed Jun 26, 2024
1 parent 963b254 commit 97562ab
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 양승민/입문/src/lec10/java/JavaAnimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lec10.java;

public abstract class JavaAnimal {

protected final String species;
protected final int legCount;

public JavaAnimal(String species, int legCount) {
this.species = species;
this.legCount = legCount;
}

abstract public void move();

public String getSpecies() {
return species;
}

public int getLegCount() {
return legCount;
}
}
12 changes: 12 additions & 0 deletions 양승민/입문/src/lec10/java/JavaCat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package lec10.java;

public class JavaCat extends JavaAnimal {
public JavaCat(String species, int legCount) {
super(species, 4);
}

@Override
public void move() {
System.out.println("꽁꽁 얼어붙은 한강 위에 고양이가 어쩌구");
}
}
7 changes: 7 additions & 0 deletions 양승민/입문/src/lec10/java/JavaFlyable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lec10.java;

public interface JavaFlyable {
default void act() {
System.out.println("파닥 파닥");
}
}
27 changes: 27 additions & 0 deletions 양승민/입문/src/lec10/java/JavaPenguin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lec10.java;

public class JavaPenguin extends JavaAnimal implements JavaSwimable, JavaFlyable{

private final int wingCount;

public JavaPenguin(String species, int legCount) {
super(species, 2);
this.wingCount = 2;
}

@Override
public void move() {
System.out.println("가자 펭귄");
}

@Override
public int getLegCount() {
return super.getLegCount() + this.wingCount;
}

@Override
public void act() {
JavaSwimable.super.act();
JavaFlyable.super.act();
}
}
7 changes: 7 additions & 0 deletions 양승민/입문/src/lec10/java/JavaSwimable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lec10.java;

public interface JavaSwimable {
default void act() {
System.out.println("어푸 어푸");
}
}
4 changes: 4 additions & 0 deletions 양승민/입문/src/lec10/java/lec10Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package lec10.java;

public class lec10Main {
}
8 changes: 8 additions & 0 deletions 양승민/입문/src/lec10/kotlin/Animal.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package lec10.kotlin

abstract class Animal(
protected val species: String,
protected open val legCount: Int
) {
abstract fun move()
}
7 changes: 7 additions & 0 deletions 양승민/입문/src/lec10/kotlin/Flyable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lec10.kotlin

interface Flyable {
fun act(){
println("파닥 파닥")
}
}
19 changes: 19 additions & 0 deletions 양승민/입문/src/lec10/kotlin/Penguin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lec10.kotlin

class Penguin(
species: String,
) : Animal(species, 2), Swimable, Flyable {

private val wingCount = 2
override fun move() {
println("가자 펭귄")
}

override val legCount
get() = super.legCount + this.wingCount

override fun act() {
super<Swimable>.act()
super<Flyable>.act()
}
}
7 changes: 7 additions & 0 deletions 양승민/입문/src/lec10/kotlin/Swimable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lec10.kotlin

interface Swimable {
fun act(){
println("어푸 어푸")
}
}
5 changes: 5 additions & 0 deletions 양승민/입문/src/lec10/kotlin/lec10Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package lec10.kotlin

fun main() {

}

0 comments on commit 97562ab

Please sign in to comment.