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

📄 5例子20.txt

📁 Java大学实用教程 耿祥义编著 课件 PPT
💻 TXT
字号:
class 锥<E>                     
{
   double height;
   E  bottom;
   public 锥(E b)
   {
      bottom=b;   
   }
   public void computerVolume()
   {
      String s=bottom.toString();
      double area=Double.parseDouble(s);
      System.out.println("体积是:"+1.0/3.0*area*height); 
   }
}
class Circle
{
   double area,radius; 
   Circle(double r)
   {
      radius=r;
   } 
   public String toString()
   {
      area=radius*radius*Math.PI;
      return ""+area;
   }
}
class Rectangle
{
   double sideA,sideB,area; 
   Rectangle(double a,double b)
   {
      sideA=a;
      sideB=b;
   } 
   public String toString()
   {
      area=sideA*sideB;
      return ""+area;
   }
}
class Example
{
   public static void main(String args[])
   {
       Circle circle=new Circle(10);
       锥<Circle> coneOne=new 锥<Circle>(circle);       //创建一个(圆)锥对象coneOne。
       coneOne.height=30;
       coneOne.computerVolume();
       Rectangle rect=new Rectangle(10,20);
       锥<Rectangle> coneTwo=new 锥<Rectangle>(rect);   //创建一个(方)锥对象coneTwo。
       coneTwo.height=10;
       coneTwo.computerVolume();
   }
}

⌨️ 快捷键说明

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