-
Notifications
You must be signed in to change notification settings - Fork 18
260616_22_진미 #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: student/22_진미
Are you sure you want to change the base?
260616_22_진미 #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # 2026-06-16 | ||
|
|
||
| ## 오늘 배운 내용 | ||
|
|
||
| - exdends 상속선언 :: public class SuperHero extends Hero { } | ||
| - super() :: 부모 생성자 호출(반드시 첫 줄에) :: public SuperHero(String name, int hp) { super(name, hp); } | ||
| - super.메소드() :: 부모 메소드(함수)도 함께 실행하고 싶을때 :: @Override public void attack(Slime slime) { super.attack(slime); } | ||
| - @Override :: 부모 메소드(함수)를 자식이 재사용 시 :: @Override public void run() { System.out.println("멋지게 퇴각했다"); } | ||
| - final :: 상속/오버라이드 금지가 되는 상수 선언 | ||
| public final class String { } // 이 클래스는 상속 불가 | ||
| public final void slip() { } // 이 메소드는 오버라이드 불가 | ||
| [ 상속 가능 is-a 원칙] :: 자식 is a 부모 와 같이 문장이 자연스러으면 되 | ||
|
|
||
| [생성자 오버로드 Overload] :: 하나의 생성자 + 타입이 다른 여러 방법의 정의 형태 | ||
| Hero() {} | ||
| Hero(String name) {} | ||
| Hero(String name, int hp) {} | ||
|
|
||
| ️ 🔐📌 초기화 값이 존재하는 부모 클래스 생성자 ➡️ 자식 클래스를 생성 가능 | ||
| [부모에 덮어쓰기 오버라이드 Override] :: | ||
| class Animal { | ||
| void speak() { System.out.println("..."); } | ||
| } | ||
| @Override ◀ 오버라이드(재정의) 할 때 꼭 쓰기 | ||
|
|
||
| ⭐ 자식:: Dog | 부모:: extends Animal ⭐ | ||
| ↓ ↓ | ||
| class Dog extends Animal { | ||
| void speak() { System.out.println("멍멍!"); } // 부모 걸 덮어씀 | ||
| } | ||
| @Override ◀ 오버라이드(재정의) 할 때 꼭 쓰기 | ||
| class Cat extends Animal { | ||
| void speak() { System.out.println("야옹~"); } | ||
| } | ||
| [⭐⭐ 인스턴트하기 위해서는 생성자가 필요 ⭐⭐] :: | ||
| public class Hero { // ← ①클래스 | ||
| private String name; | ||
| private int hp; | ||
| public Hero(String name, int hp) { // ← ②생성자 | ||
| this.name = name; | ||
| this.hp = hp; | ||
| } | ||
| Hero hero = new Hero("홍길동", 100); // ← ③인스턴스 | ||
| } | ||
|
Comment on lines
+36
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 샘플이 문법적으로 유효하지 않습니다. 라인 43의 🔧 권장 수정안옵션 1: public class Hero {
private String name;
private int hp;
public Hero(String name, int hp) {
this.name = name;
this.hp = hp;
}
- Hero hero = new Hero("홍길동", 100);
+ public static void main(String[] args) {
+ Hero hero = new Hero("홍길동", 100);
+ }
}옵션 2: 설명 텍스트로 변경 - Hero hero = new Hero("홍길동", 100);
+ // 인스턴스 생성 예시:
+ // Hero hero = new Hero("홍길동", 100);옵션 3: 인스턴스 생성을 별도 섹션으로 분리 코드 샘플을 클래스 정의 부분과 사용 부분으로 명확히 분리하면 혼동을 줄일 수 있습니다. 🤖 Prompt for AI Agents |
||
| [ getter / setter 주로 쓰는 경우 ] :: | ||
|
|
||
| - private 변수 접근할 때 | ||
| - 값 검증 시 | ||
| - final 상수는 getter만 사용 | ||
|
|
||
| [단축키] :: | ||
| - Ctrl+Alt :: 함수가 작성된 실제 위치로 이동 | ||
| - Ctrl+B :: 함수 상속 위치 이동 | ||
| - shift + F6 :: 이미 정해진 클래스 함수의 이름을 전체 변경하려 할때 | ||
|
|
||
| ## 기억해야 할 내용 | ||
|
|
||
| - TEST코드 파일은 항상 따로 만들어야 한다 | ||
| [테스트 파일 생성법] | ||
| 테스트 할 클래스 변수 클릭 ➡️ Generate ➡️ TEST 선택 ➡️ 해당 파일의 TEST 파일 생성 | ||
| - ex) WandTest (@Test) 항상 짝궁! 같이 있어야 한다 | ||
| [순서] | ||
| class 테스트이름Test { | ||
| ↓ | ||
| @Test | ||
| ↓ | ||
| void 테스트메소드() { } | ||
|
|
||
| ## 실습 코드 | ||
|
|
||
| ```java | ||
| public class Cleric { | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @startuml | ||
| scale 3 | ||
|
|
||
| class SuperHero exdends Hero{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 4의 🤖 Prompt for AI Agents |
||
| +void setFlying(bool flying) | ||
| +bool isflying() | ||
| } | ||
|
|
||
| class Hero{ | ||
| -int hp | ||
| -String name | ||
|
|
||
| +void attack() | ||
| } | ||
|
|
||
| class wizard{} | ||
|
|
||
| @enduml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class Hero { | ||
| private int hp; | ||
|
|
||
| public Hero(int hp) { | ||
| this.hp = hp; | ||
| } | ||
|
|
||
| public int getHp() { | ||
| return hp; | ||
| } | ||
|
|
||
| public void setHp(int hp) { | ||
| this.hp = hp; | ||
| } | ||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HP 하한 검증이 없어 전투 로직이 역전될 수 있습니다. Line 14-16에서 음수 HP를 허용하면, 이후 독 데미지 계산에서 음수 데미지가 발생해 실제로 HP가 증가할 수 있습니다. 🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.survivalcoding; | ||
| //Slime (부모) -> Extends Slime(자식) | ||
|
|
||
| public class PoisonSlime extends Slime { | ||
| private int poisonCnt = 5; | ||
|
|
||
| public PoisonSlime(String suffix) { | ||
| super(suffix); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void attack(Hero hero) { | ||
| super.attack(hero); | ||
| if (poisonCnt > 0) { | ||
| System.out.println("슬라임 " + suffix + " 독 살포!"); | ||
| int damage = hero.getHp() / 5; | ||
| hero.setHp(hero.getHp() - damage); | ||
| System.out.println(damage + " 포인트 데미지"); | ||
| poisonCnt--; | ||
| } | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class Slime { | ||
| final String suffix; //suffix은 슬라임 이름 | ||
| int hp; | ||
|
|
||
| public Slime(String suffix) { | ||
| this.suffix = suffix; //값이 초기화 된 부모 생성자 ▶ 자식 클랙스에서 빨간 줄 없이 잘 굴러감 | ||
| } | ||
|
|
||
| void attack(Hero hero) { | ||
| System.out.println("=========================="); | ||
| System.out.println("슬라임 " + suffix + " 이(가) 공격했다"); | ||
| System.out.println("10 의 데미지"); | ||
| hero.setHp(hero.getHp() - 10); | ||
| System.out.println("--------------------------"); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class PoisonSlimeTest { | ||
|
|
||
| @Test | ||
| void attack() { | ||
| Hero h = new Hero(100); | ||
| PoisonSlime ps = new PoisonSlime("홍길홍길"); | ||
| ps.attack(h); | ||
| assertEquals(72, h.getHp()); | ||
| System.out.println("=========================="); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성자 오버로드 예시가 실제 저장소 코드와 불일치합니다.
두 TIL 문서(2026-06-15, 2026-06-16)의 생성자 오버로드 예시는 모두 동일한 근본 원인으로 인한 문제입니다. 제시된
Hero()/Hero(String name)/Hero(String name, int hp)예시는 현재 저장소의Hero.java에 존재하지 않으며, 실제 구현은Hero(int hp)생성자만 가지고 있습니다. 학습 자료로서 정확성이 중요하므로 두 문서를 모두 수정해 주세요.TIL/sample/2026-06-15-정리.md#L43-L46: 생성자 오버로드 예시를 실제 Hero.java와 일치하도록 수정TIL/sample/2026-06-16-정리.md#L14-L17: 동일하게 예시를 실제 코드와 일치하도록 수정, 또는 더 일반적인 생성자 오버로드 설명으로 변경📍 Affects 2 files
TIL/sample/2026-06-15-정리.md#L43-L46(this comment)TIL/sample/2026-06-16-정리.md#L14-L17🤖 Prompt for AI Agents