实验八 接口与实现接口的类
實(shí)驗(yàn)八 接口與實(shí)現(xiàn)接口的類
?
一.程序代碼
public class yuanzhui extends Rectangle implements Area,Volume {
private double radius;?
private double length;
private double height;
public yuanzhui(double radius,double length,double height)
{
this.radius = radius;
this.length = length;
this.height = height;
}
public yuanzhui()
{
this(0,0,0);
}
public double area() //計(jì)算圓錐的表面積,實(shí)現(xiàn)Area接口中的抽象方法
{
return Math.PI*this.radius*this.length+Math.PI*this.radius* this.radius ;
}
public double volume() //計(jì)算圓錐的體積,實(shí)現(xiàn)Volume接口中的抽象方法
{
return Math.PI * this.radius * this.radius * this.height/3;
}
public String toString()
{
return "一個(gè)圓錐,半徑"+this.radius+",高"+this.height+",斜邊,"+this.length+"表面積為"+this.area()+",體積為"+this.volume();
}
public static void main(String args[])
{
System.out.println(new yuanzhui(12,8,6).toString());
}
}
二.實(shí)驗(yàn)心得
1.通過本次實(shí)驗(yàn)的調(diào)試,使我清楚的認(rèn)識(shí)到接口在JAVA編程語言中是一個(gè)抽象類型,是抽象方法的集合,
接口通常以interface來聲明。
2.一個(gè)類通過繼承接口的方式從而來繼承接口的抽象方法。
3.接口并不是類,編寫接口的方式和類很相似,但是它們屬于不同的概念。類描述對(duì)象的屬性和方法。接口則包含類要實(shí)現(xiàn)的方法。
?
轉(zhuǎn)載于:https://www.cnblogs.com/MWH0979/p/10896406.html
總結(jié)
以上是生活随笔為你收集整理的实验八 接口与实现接口的类的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一道关于信号量的问题
- 下一篇: 浏览器与服务器通信技术——Ajax详解