Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- * Write a program to calculate Cylinder area. Program should have class called
- * Cylinder with radius and height as member variables and getArea member method.
- * getArea method should print area of the Cylinder object.
- */
- class Cylinder{
- int r;
- int h;
- void setData(int x, int y){
- r = x;
- h = y;
- }
- void getArea(){
- //total area of cylinder is = (2 * pi * r * r) + (2 * pi * r * h)
- System.out.println("Area of Cylinder: " + (2* 3.14f * r * r) + (2* 3.14f * r * h));
- }
- }
- public class CylinderArea
- {
- public static void main(String args[]){
- Cylinder c1 = new Cylinder();
- c1.setData(10, 4);
- c1.getArea();
- Cylinder c2 = new Cylinder();
- c2.setData(3,4);
- c2.getArea();
- }
- }

Hi, This is
Post new comment