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

📄 shapeinterfacetest.java

📁 《Java核心技术应用开发》电子工业出版社书籍源代码
💻 JAVA
字号:
package sample;

public class ShapeInterfaceTest {

  public static void main(String[] args) {
    Shape circle1=new Circle(2.0,3.0,5.0);
    Shape rectangle1=new Rectangle(3.4,6.8,433,6567);
    circle1.draw();
    rectangle1.draw();
  }
}

interface Shape
{
  public abstract void draw();
  //{
    //System.out.println("draw in shape");
  //}
}

  class Circle implements Shape
  {
    private double x;
    private double y;
    private double r;

    Circle()
    {
      r=1.0;
    }

    Circle(double nr)
    {
      r=nr;
    }
    Circle(double x, double y,double r)
    {
      this.x = x;
      this.y = y;
      this.r = r;
    }

    public void draw()
    {
      System.out.println("draw in circle");
      System.out.println("x: " + x + "\n" + "y :" + y + "\n" + "r: " + r);
    }
  }


class Rectangle implements Shape
{
  private double x;
  private double y;
  private double height;
  private double width;

  Rectangle()
  {
    height=1.0;
    width=1.0;
  }
  Rectangle(double nheight,double nwidth)
  {
    height=nheight;
    width=nwidth;
  }
  Rectangle(double nx,double ny,double nheight,double nwidth)
  {
    this.x = nx;
    this.y = ny;
    height=nheight;
    width=nwidth;
  }
  public void draw()
  {
    System.out.println("draw in rectangle");
    System.out.println("x: " + x + "\n" + "y :" + y + "\n" +
                       "height: " + height + "\n" + "weight: " + width);
  }
}

⌨️ 快捷键说明

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