반응형
Q.Board 클래스의 생성자가 다음과 같이 오버로딩되어 있습니다. 생성자마다 중복 코딩된 부분이 있습니다. this( )를 활용해서 중복 코드를 제거해보세요.
public class Board {
String title;
String content;
String writer;
String date;
int hitcount;
Board(String title, String content){
this.title = title;
this.content = content;
this.writer = "로그인한 회원아이디";
this.date = "현재 컴퓨터 날짜";
this.hitcount = 0;
}
Board(String title, String content, String writer){
this.title = title;
this.content = content;
this.writer = writer;
this.date = "현재 컴퓨터 날짜";
this.hitcount = 0;
}
Board(String title, String content, String writer, String date){
this.title = title;
this.content = content;
this.writer = writer;
this.date = date;
this.hitcount = 0;
}
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;
}
public class Board {
String title;
String content;
String writer;
String date;
int hitcount;
Board(String title, String content){
this.title = title;
this.content = content;
this.writer = "로그인한 회원아이디";
this.date = "현재 컴퓨터 날짜";
this.hitcount = 0;
}
Board(String title, String content, String writer){
this(title, content);
this.writer = writer;
}
Board(String title, String content, String writer, String date){
this(title, content, writer);
this.date = date;
}
Board(String title, String content, String writer, String date, int hitcount){
this(title, content, writer, date);
this.hitcount = hitcount;
}
}
반응형
'프로그래밍 공부 > java' 카테고리의 다른 글
[JAVA] 상속 (0) | 2023.01.06 |
---|---|
[JAVA] 매크로 작성을 위한 팁 모음 (0) | 2023.01.03 |
[JAVA] 클래스와 객체 - 객체 배열, 메소드, 접근지정자, static, final클래스 (0) | 2022.12.30 |
[JAVA] 클래스와 객체 - 생성자, this레퍼런스 (0) | 2022.12.21 |
[JAVA] 클래스와 객체 - 객체지향과 자바 , 자바 클래스 만들기 (0) | 2022.12.20 |