Java program to find area of circle using class and object

Let’s learn java program to find area of circle using class and object.

Java program to find area of circle using class and object

We can also find area of circle using class and object.

To calculate area and circumference of circle using given radius first create class Circle, variable/field radius methods findArea(), findCircumference() and setValues().

Here’s the java program to find or calculate area of circle using class and object.

class Circle
{
   double radius;
   void setValues(double rad)
   {
      radius = rad;
   }
   void findArea()
   {
      double circleArea = Math.PI * radius * radius;
      System.out.println("Area of circle = " + circleArea);
   }
   void findCircumference()
   {
      double circleCircumference = 2 * Math.PI * radius;
      System.out.println("Circumference of circle = " + circleCircumference);
   }
   public static void main(String[] args)
   {
      Circle obj = new Circle();
      obj.setValues(5);
      obj.findArea();
      obj.findCircumference();
   }
}


Output:

Area of circle = 78.53981633974483
Circumference of circle = 31.41592653589793


Do not stop learning learn java programming and learn how to code.