[Point 클래스 소스]


package superclass;
public class Point {
 int x;
 int y;
 public Point( )
{
 x = y = 0;
}
public Point(int x, int y)
{
 this.x = x;
 this.y = y;
}
public void setXY(int x, int y)
{
 this.x = x;
 this.y = y;
}
public String toString( )
{
 return String.format("슈퍼클래스: ( %d, %d ) ", x, y);
}
}


[PointTest 클래스 소스]


package superclass;

public class pointTest extends Point  {
 int x;
 int y;
public pointTest(int a, int b, int c, int d)
{
 super.x = a;  // 7~8번행 super(a, b);로 변경 가능
 super.y = b;
 this.x = c;
 this.y = d; 
}
public void setXY(int x, int y)
{
 super.setXY(x, y);
}
public String toString( )
{
 String str = " ";
 return str += super.toString( ) + "서브클래스: ( " + this.x + ", " + this.y + " )";
}
public static void main(String [ ] args)
{
 pointTest pt = new pointTest(10, 20, 30, 40);
 System.out.println(pt.toString( ));
 pt.setXY(100, 120);
 System.out.println(pt.toString());
}
}