Write a program to calculate the area of a circle using static and non static variables.
[JAVA only]
Answers
public class Circle
{
static double PI = 3.145;
int radius;
public void setRadius(int r)
{
radius = r;
}
public double calculateArea()
{
double area = PI * (radius * radius);
return area;
}
public static void main(String args[ ])
{
int radius = 4;
double result;
Circle myCircle = new Circle();
myCircle.setRadius(Rad);
result = myCircle.calculateArea();
System.out.println(''Value of PI is : '' + Circle.PI);
System.out.println(''Radius of circle is : '' myCircle.radius);
System.out.prinltn(''Area of circle is : '' + result);
}
}
The output will be :
Value of PI is : 3.1415
Radius of circle is : 4
Area of circle is : 50.264