class Point
{ private int x,y;
public Point(int x,int y)
{
this.x=x; //this它代表当前对象名
this.y=y;
}
public void Draw()
{
}
public Point()
{
this(0,0); //this(参数)调用本类中另一种形成的构造函数
}
}
class Circle extends Point
{
private int radius;
public circle(int x0,int y0, int r )
{
super(x0,y0); //super(参数)调用基类中的某一个构造函数
radius=r;
}
public void Draw()
{
super.Draw(); //super它引用当前对象的直接父类中的成员
drawCircle();
}}
{ private int x,y;
public Point(int x,int y)
{
this.x=x; //this它代表当前对象名
this.y=y;
}
public void Draw()
{
}
public Point()
{
this(0,0); //this(参数)调用本类中另一种形成的构造函数
}
}
class Circle extends Point
{
private int radius;
public circle(int x0,int y0, int r )
{
super(x0,y0); //super(参数)调用基类中的某一个构造函数
radius=r;
}
public void Draw()
{
super.Draw(); //super它引用当前对象的直接父类中的成员
drawCircle();
}}
本文介绍了一个简单的面向对象设计案例,包含两个类:Point和Circle。Point类用于表示二维坐标中的一个点,Circle类继承自Point类并添加了半径属性,实现了圆形的绘制方法。
1145

被折叠的 条评论
为什么被折叠?



