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

📄 testoverridemethods.java

📁 学生综测系统 不会吧 大哥 下个东西这么烦啊
💻 JAVA
字号:
// TestOverrideMethods.java: Test the Cylinder class that overrides
// its superclass's methods
public class TestOverrideMethods
{
  public static void main(String[] args)
  {
    Cylinder myCylinder = new Cylinder(5.0, 2.0);
    System.out.println("The length is " + myCylinder.getLength());
    System.out.println("The radius is " + myCylinder.getRadius());
    System.out.println("The surface area of the cylinder is "+
      myCylinder.findArea());
    System.out.println("The volume of the cylinder is "+
      myCylinder.findVolume());  
  }
}
/*
// New cylinder class that overrides the findArea() method defined in
// the circle class
class Cylinder extends Circle
{
  private double length;

  // Default constructor
  public Cylinder()
  {
    super();
    length = 1.0;
  }

  // Construct a cylinder with specified radius and length
  public Cylinder(double r, double l)
  {
    super(r);
    length = l;
  }

  // Getter method for length
  public double getLength()
  {
    return length;
  }

  // Find cylinder surface area
  public double findArea()
  {
    return 2*super.findArea()+(2*getRadius()*Math.PI)*length;
  }

  // Find cylinder volume
  public double findVolume()
  {
    return super.findArea()*length;
  }
} */

⌨️ 快捷键说明

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