package com.ctgu.java; public class Circle { private double radius; public Circle(){ this.radius = 1; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double findArea(){ return Math.PI* radius*radius; } } package com.ctgu.java; public class Cylinder extends Circle { private double length; public Cylinder(){ length = 1; } public double getLength() { return length; } public void setLength(double length) { this.length = length; } public double findVolume(){ //return Math.PI*this.getRadius()*this.getRadius()*length; return findArea()*length; } } package com.ctgu.java; public class TestCylinder { public static void main(String[] args) { Cylinder c = new Cylinder(); double area = c.findVolume(); System.err.println(area); c.setRadius(2.3); c.setLength(1.2); area = c.findVolume(); System.out.println(area); } }
时间: 2024-11-07 17:41:29