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 Circle area. Program should have class called
- * Circle with radius as member variable and getArea member method.
- * getArea method should print area of the Circle object.
- */
- class Circle{
- int r;
- void setData(int x){
- r = x;
- }
- void getArea(){
- //area of circle is = pi * r * r
- System.out.println("Area of Circle: " + (3.14 * r * r));
- }
- }
- public class CircleArea
- {
- public static void main(String args[]){
- Circle c1 = new Circle();
- c1.setData(10);
- c1.getArea();
- Circle c2 = new Circle();
- c2.setData(4);
- c2.getArea();
- }
- }

Post new comment