국비교육/국비교육 복습
Day09_oop.basic2 : 객체 생성 연습 (1)
Luver Duck
2022. 8. 7. 20:46
(Q) 다음 데이터를 객체로 만들어 정보를 저장하고 출력하세요

Country 클래스
package day09_oop.basic2;
public class Country {
// 필드 생성
int rank;
String name;
double score;
//출력 메소드
void print() {
System.out.println("순위 : " + this.rank);
System.out.println("국가 : " + this.name);
System.out.println("점수 : " + this.score);
System.out.println();
}
}
Test01
package day09_oop.basic2;
public class Test01 {
public static void main(String[] args) {
// 브라질 객체 생성
Country a = new Country();
a.rank = 1;
a.name = "브라질";
a.score = 1828.45;
// 벨기에 객체 생성
Country b = new Country();
b.rank = 2;
b.name = "벨기에";
b.score = 1823.45;
// 프랑스 객체 생성
Country c = new Country();
c.rank = 3;
c.name = "프랑스";
c.score = 1786.15;
// 나라 정보 출력
a.print();
b.print();
c.print();
}
}