Untitled

Untitled

내 풀이, 답

package variable;

public class Book {
	 String title; //제목
	 String author; //저자
	 int page; //페이지 수
	
	 //기본 생성자
	 Book() {
	 		this(" "," ",0); //기본생성자 개선
//		this.title = " ";
//		this.author = " "; 
	 }
	 
	 //생성자
	 Book(String title, String author) {
//		this.title = title;
//		this.author = author; 
		this(title, author, 0);
	 }
	 //생성자
	 Book(String title, String author, int page) {
//		 this(title,author);
//		 this.page = page;
		 this.title= title;
		 this.author = author;
		 this.page = page;
	 }
	 
	 //메서드
	 void displayInfo(){
		System.out.println("제목:" + title + ", 저자:" + author + ", 페이지:" + page);
	 }
	 
}
package variable;

public class BookMain {

	public static void main(String[] args) {
		Book book1 = new Book();
		book1.displayInfo();
		 
		 // title과 author만을 매개변수로 받는 생성자
		 Book book2 = new Book("Hello Java", "Seo");
		 book2.displayInfo();
		 
		 // 모든 필드를 매개변수로 받는 생성자
		 Book book3 = new Book("JPA 프로그래밍", "kim", 700);
		 book3.displayInfo();
	}
}