本文主要是介绍面向对象(进阶)继承性 例题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
父类
package mianxiangduixiang02;public class Circle05 {private double radius;public Circle05(){this.radius=1;}public double getRadius() {return radius;}public void setRadius(double radius) {this.radius = radius;}public double findArea(){return 3.14*radius*radius;}
}
子类
package mianxiangduixiang02;public class Cylinder05 extends Circle05{private double length;public Cylinder05(){length=1;}public double getLength() {return length;}public void setLength(double length) {this.length = length;}public double findVolumn(){return findArea()*length;}
}
测试
package mianxiangduixiang02;public class CylinderTest05 {public static void main(String[] args) {Cylinder05 c1=new Cylinder05();c1.setLength(2.5);c1.setRadius(2.5);System.out.println(c1.findVolumn());System.out.println("底面面积为"+c1.findArea());}}
这篇关于面向对象(进阶)继承性 例题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!