강의

멘토링

커뮤니티

Inflearn Community Q&A

No author

This post's author information has been deleted.

Learning Java through Pictures, Part 2: Object Orientation!

Reference? Static?

출력값이 다르다고 나오네요!

Written on

·

310

·

Edited

0

클라우드 스터딩에서 실행은 되는데 오류 없이 출력값이 다르다고 나오네요

강의에서 알려주신 코드가 아니라 제 마음대로 코드를 짜서 그런가요?

 코드 최대한 안따라하고 혼자 해보려고 했는데 잘못된 부분많을까요?ㅠ

 

public class Starcraft {

public static void main(String[] args) {

// 객체 생성

Marine ma = new Marine("레이너", 80);

Medic me = new Medic("모랄레스", 60, 60);

// 마린의 스팀팩!

ma.steam();

// 메딕의 힐!

me.heal(ma);

}

}

// 정보 클래스

class Marine {

String name;

int hp;

Marine(String name, int hp) {

this.name = name;

this.hp = hp;

}

void steam() {

System.out.printf("[%s]의 스팀팩! Hp: %d -> %d\n", name, hp, hp-10);

hp = hp-10;

}

}

class Medic {

String name;

int hp;

int mp;

Medic(String name, int hp, int mp) {

this.name = name;

this.hp = hp;

this.mp = mp;

}

void heal(Marine ma) {

System.out.printf("[%s]의 치유! => [%s] Hp(%d -> %d)", name, ma.name, ma.hp, ma.hp+10);

ma.hp = ma.hp + 10;

}

}

java객체지향

Answer 1

0

hongpark님의 프로필 이미지
hongpark
Instructor

코드를 "스크린샷"
또는 "코드블럭"으로해서
다음 형식으로 올려보셈


실행코드

여기는 실행코드

 

실행결과

여기는 실행결과


image

No author

This post's author information has been deleted.

Ask a question