일단 부모클래스
public class Phone {
private int areaCode;
private int prefix;
private int lineNumber;
public Phone(int ac, int p, int ln) {
areaCode = ((ac > 0 && ac < 1000) ? ac : 555);
prefix = ((p > 0 && p < 1000) ? p : 555);
lineNumber = ((ln > 0 && ln < 10000) ? ln : 5555);
}
public String makeCall(Phone p) {
return "Dialing " + p.toString();
}
public String toString() {
return "" + areaCode + "-" + prefix + "-" + lineNumber;
}
-------------------------------------------------------
아래는 자식 클래스
public class CellPhone extends Phone {
private double longitude;
private double latitude;
public CellPhone(int ac, int p, int ln, double lat, double lng) {
super(ac, p, ln);
latitude = lat;
longitude = lng;
}
public void updateLocation() {
// uses GPS to get the updated values for longitude and latitude
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
public String toString() {
String s = super.toString();
return s + "; (" + longitude + ", " + latitude + ")";
}
}
-----------------------------------------------
메인에다가 아래 세줄 돌리면
Phone ph = new CellPhone(444, 555, 6666, 1.2, 2.4);
String s = ph.toString();
System.out.println(s);
ph.toString이라고 했으니까
Phone 클래스의 toString이 트리거 되어야 하는거 아니야?
형변환이자나 병신아 으이구 ㅉㅉ
상속이면 형변환되는거야?
ph를인스턴스 하면서 리턴하는게 자식이자나 병신아
감사함미다