Recursive constructor invocation Person(int, int, int, int)
- 카테고리 없음
- 2015. 7. 21. 23:25
package IdontStudyJava;
class Person {
private int perID;
private int milID;
private int phone;
private int zip;
public Person(int pID, int mID) {
perID = pID;
milID = mID;
}
public Person(int pID) {
perID = pID;
milID = 0;
}
public Person(int pID, int mID, int phone, int zip) {
this(pID, mID, phone, zip);
}
public void showInfo() {
System.out.println("민번 : " + perID);
System.out.println("폰번 : " + phone);
System.out.println("우편번호 : " + zip);
if (milID != 0) {
System.out.println("군번 : " + milID + "\n");
} else
System.out.println("군과 관계 없음");
}
}
public class Overloading {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person man = new Person(891103, 1076075014, 4943, 293);
Person woman = new Person(950404);
man.showInfo();
woman.showInfo();
}
}
Recursive constructor invocation Person(int, int, int, int)
오류가 떴었음. 이런식으로 수정하면됌.
정말 어이없는 실수 했던거임.
오버로딩된 다른 생성자의 호출을 요구해야하는데 헛짓한것임.
package IdontStudyJava;
class Person {
private int perID;
private int milID;
private int phone;
private int zip;
public Person(int pID, int mID) {
this(pID,mID,0,0);
}
public Person(int pID) {
perID = pID;
milID = 0;
}
public Person(int pID, int mID, int phone, int zip) {
perID = pID;
milID = mID;
this.phone = phone;
this.zip = zip;
}
public void showInfo() {
System.out.println("민번 : " + perID);
System.out.println("폰번 : " + phone);
System.out.println("우편번호 : " + zip);
if (milID != 0) {
System.out.println("군번 : " + milID + "\n");
} else
System.out.println("군과 관계 없음");
}
}
public class Overloading {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person man = new Person(891103, 1076075014, 4943, 293);
Person woman = new Person(950404);
man.showInfo();
woman.showInfo();
}
}
이 글을 공유하기