📄 例6.5.txt
字号:
//例6.5:接口扩展举例。
interface Shape
{
double pi=3.14;
void setColor(String str);
}
interface Shape2D extends Shape
{
double getArea();
}
class Box implements Shape2D
{
double r,h;String c;
public Box(double r,double h)
{
this.r=r;
this.h=h;
}
public double getArea() //实现接口的抽象方法
{
return (pi*r*r);
}
public void setColor(String c) //实现父接口的抽象方法
{
this.c=c;
}
public static void main(String args[])
{
Box box=new Box(2.0,5.0);
System.out.println("该盒式容器的颜色为"+box.c);
System.out.println("\n该盒式容器的容积为"+box.h*box.getArea());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -