Back-end/Java
[Java] 혼자 공부하는 자바 245~246p 풀어보기
디팔⸜( ◜࿁◝ )⸝︎︎
2022. 9. 14. 16:04
문제 3번
클래스 생성자의 중복을 this()를 이용하여 제거해보세요.
package com.example.MyJavaProject;
class Main {
public static void main(String[] args) {
}
}
class Board{
String title;
String content;
String writer;
String date;
int hitcount;
Board(String title, String content){
this(title, content, "Charles", "3/14", 100);
}
Board(String title, String content, String writer){
this(title, content, writer, "3/14", 100);
}
Board(String title, String content, String writer, String date){
this(title, content, writer, date, 100);
}
Board(String title, String content, String writer, String date, int hitcount){
this.title = title;
this.content = content;
this.writer = writer;
this.date = date;
this.hitcount = hitcount;
}
}