⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例6.8.txt

📁 《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌-源程序
💻 TXT
字号:
//例6.8:构造方法的调用顺序举例1,分析下面程序的功能。
class Point
{
    private double xCoordinate;
    private double yCoordinate;
    public Point(){}
    public Point(double x,double y)
    {
      xCoordinate=x;
      yCoordinate=y;
    }
    public String toString()
    {
     return "("+Double.toString(xCoordinate)+","+Double.toString(yCoordinate)+")";
    }
     //下面还可以有其它方法
}
public class Ball
{
   private Point center;         //中心点
   private double radius;        //半径
   private String colour;        //颜色
   public Ball(){}
   public Ball(double x,double y,double r)//具有中心点及半径的构造方法
   {
     center=new Point( x,y);              //调用类Point的构造方法
     radius=r;
   }
   public Ball(double x,double y,double r,String c)//具有中心点、半径及颜色的方法
   {
     this(x,y,r);                      //调用Ball(doublb x,double y,double r)
     colour=c;
   }
   public String toString()
    {
     return"一个球中心在"+center.toString()+",半径等于"+Double.toString(radius)+"颜色为"+colour;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -