제발 도와주세요!!ㅜㅜㅠㅠ자바 오버라이딩 질문!!
-
게시물 수정 , 삭제는 로그인 필요
자바 오버라이딩 하는데 너무 어려워서 질문드립니다 ㅜㅜ!! 이렇게 코드를 짰는데 Place , Company, University 의 각각에 오버라이딩을 활용해 toString 메서드랑 introduce 메서드를 만들고. tosString 메서드는 title = 제목 nRooms = 방 수 nEmployees = 종업원 수 이런식으로 그냥 그 뜻 의미만 정의하기. 를 하고싶습니다!! 어떻게 해야될까요 ㅜ?
class Place {
private String title;
private int nRooms;
private String location;
public Place(String title, int nRooms, String location) {
super();
this.title = title;
this.nRooms = nRooms;
this.location = location;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getnRooms() {
return nRooms;
}
public void setnRooms(int nRooms) {
this.nRooms = nRooms;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
<pre>class University extends Place {
private int rank;
private int nStudents;
private int nTeachers;
public University(String title, int nRooms, String location, int rank, int nStudents,
int nTeachers) {
super(title, nRooms, location);
this.rank = rank;
this.nStudents = nStudents;
this.nTeachers = nTeachers;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public int getnStudents() {
return nStudents;
}
public void setnStudents(int nStudents) {
this.nStudents = nStudents;
}
public int getnTeachers() {
return nTeachers;
}
public void setnTeachers(int nTeachers) {
this.nTeachers = nTeachers;
}
}
코드를 짰는데 Place , Company, University 의 각각에 오버라이딩을 활용해 toString 메서드랑 introduce 메서드를 만들고. tosString 메서드는 title = 제목 nRooms = 방 수 nEmployees = 종업원 수 이런식으로 그냥 그 뜻 의미만 정의하기. 를 하고싶습니다!! 어떻게 해야될까요 ㅜ?
class Place {
private String title;
private int nRooms;
private String location;
public Place(String title, int nRooms, String location) {
super();
this.title = title;
this.nRooms = nRooms;
this.location = location;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getnRooms() {
return nRooms;
}
public void setnRooms(int nRooms) {
this.nRooms = nRooms;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
<pre>class University extends Place {
private int rank;
private int nStudents;
private int nTeachers;
public University(String title, int nRooms, String location, int rank, int nStudents,
int nTeachers) {
super(title, nRooms, location);
this.rank = rank;
this.nStudents = nStudents;
this.nTeachers = nTeachers;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public int getnStudents() {
return nStudents;
}
public void setnStudents(int nStudents) {
this.nStudents = nStudents;
}
public int getnTeachers() {
return nTeachers;
}
public void setnTeachers(int nTeachers) {
this.nTeachers = nTeachers;
}
}