-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week1][입문편] 3강 코틀린에서 상속을 다루는 방법 (#5)
- Loading branch information
Showing
11 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("꽁꽁 얼어붙은 한강 위에 고양이가 어쩌구"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("파닥 파닥"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("어푸 어푸"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package lec10.java; | ||
|
||
public class lec10Main { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lec10.kotlin | ||
|
||
interface Flyable { | ||
fun act(){ | ||
println("파닥 파닥") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lec10.kotlin | ||
|
||
interface Swimable { | ||
fun act(){ | ||
println("어푸 어푸") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lec10.kotlin | ||
|
||
fun main() { | ||
|
||
} |