JAVA/chapter06_oop

chapter01 : book / book_main

GAWON 2023. 5. 26. 17:38
package org.joonzis.ex;

public class Ex01_Book {
	// 필드
	String title;
	String writer;
	int price;
	boolean isBestSeller;
	
	// 메소드
	void info() {
		System.out.println("제목 : " + title);
		System.out.println("저자 : " + writer);
		System.out.println("가격 : " + price);
		System.out.println(isBestSeller ? "베스트셀러" : "일반서적");
	}
	
	
}
package org.joonzis.ex;

public class Ex01_BookMain {
	public static void main(String[] args) {
		
		// 1. Book 객체(인스턴스) 생성
		Ex01_Book myBook = new Ex01_Book();
		
		// 2. 생성된 객체(myBook) 활용
		myBook.title = "자바의 정석";
		myBook.writer = "남궁성";
		myBook.price = 35000;
		myBook.isBestSeller = true;
		
		myBook.info();
	}
}