class MyClassCircle {
private double radius;
MyClassCircle(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
}
class GetAreaDemo {
public static void main(String [] args) {
MyClassCircle circle = new MyClassCircle(5.6);
System.out.println("Area of the circle with radius 5.6 equal to " + cicle.getArea());
}
}
What is the use/uses of variable, double radius and MyClassCircle in the program?
SOLUTION TO THE ABOVE QUESTION
ANSWER.
I)The variable radius is an attribute of the entity circle which stores a value used to calculate the area of the circle using the formula area = PI*radius*radius
II)The variable MyClassCircle is a class name which is used to create an object circle which is used to perform all operations related to the object circle like calculating its area by invoking the method getArea() i.e. (circle.getArea())
Comments
Leave a comment