//package chapter8.example8_2; /** * Title: Chapter 8, "Class Inheritance and Interfaces" * Description: Examples for Chapter 8 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // Cylinder.java: New cylinder class that overrides the findArea() // method defined in the circle class // Place in the package chapter8.example8_2 to avoid naming conflict import chapter6.CircleWithAccessors; public class Cylinder extends CircleWithAccessors { /**length of this cylinder*/ private double length; /**Default constructor*/ public Cylinder() { super(); length = 1.0; } /**Construct a cylinder with specified radius and length*/ public Cylinder(double r, double l) { super(r); length = l; } /**Return length*/ public double getLength() { return length; } /**Return the surface area of this cylinder. The formula is * 2*circle area + cylinder body area */ public double findArea() { return 2*super.findArea()+(2*getRadius()*Math.PI)*length; } /**Return the volume of this cylinder*/ public double findVolume() { return super.findArea()*length; } }