(Method)Overriding
class Point {
int x;
int y;
String getLocation() {
return "x :" + x + ",y :"+y;
}
}
class Point3D extends Point {
int z;
//Method declaration does not change, but contents change.
String getLocation() {
return "x :" + x + ",y : "+y + ",z : "+z;
}
}class Point extends Object{
int x;
int y;
//Object클래스의 toString()을 오버라이딩.
public String getLocation() {//선언부는 똑같아야함!
return "x :" + x + ",y :"+y;
}
}
class Point3D extends Point {
int z;
//Method declaration does not change, but contents change.
String getLocation() {
return "x :" + x + ",y : "+y + ",z : "+z;
}
}Last updated