Create a class named MyClassCircle containing a parameterized constrictor of the class and a method name getArea(l that will calculate the area of the circle. Create another class names GetAreaDemo() that will contain the main method that will supply the arguments and display its output using the standard output stream.
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());
}
}
Comments
Leave a comment