Write a program to find the area of circle using default constructor

Write a program to find the area of circle using default constructor
class circle
{
private int r;
public circle()
{
r=1;
}
public void set(int n)
{
r=n;
}
public void area()
{
double a=3.14*r*r;
System.out.println(“area is “+a);
}
}
class test
{
public static void main(String args[])
{
circle a=new circle();
circle b=new circle();
a.set(5);
b.set(10);
a.area();
b.area();
}
}

Output:
area is 78.5
area is 314.0

Leave a Reply

Your email address will not be published. Required fields are marked *