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

📄 例5.7.txt

📁 《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌-源程序
💻 TXT
字号:
//例5.7:分析下面程序的输出结果,熟悉抽象类和抽象方法的定义和使用。
abstract class Shape
{
	public abstract double 求面积();
}
class 梯形 extends Shape
{
	double a,b,h;
	梯形(double a,double b,double h)
	{
		this.a=a;this.b=b;this.h=h;
	}
	public double 求面积()
	{
		return((a+b)*h*0.5);
	}
}
class 圆形 extends Shape
{
	double r;
	圆形(double r)
	{
		this.r=r;
	}
	public double 求面积()
	{
		return(Math.PI*r*r);
	}
}
public class Abstractshape
{
	public static void main(String args[])
	{
		Shape trapzoid = new 梯形(2.0,7.0,10);	
		Shape oval = new 圆形(2.0);
		System.out.println("梯形面积"+trapzoid.求面积());
		System.out.println("圆形面积"+oval.求面积());		
	}	
}

⌨️ 快捷键说明

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