Create a class cylinder with attributes radius and height, each of which has a
default value of 10. Provide a method that calculates the cylinder's volume, which is pi
multiplied by the square of the radius and by the height. It has the set and get Methods
for both radius and height. The set method should verify that radius and height are
positive number. Write a program to test class cylinder. (java)
Answers
Answer:abstract class Shape
{
abstract void RectangleArea(float length , float breadth);
abstract void SquareArea(float radius);
abstract void CircleArea(float side);
}
class Area extends Shape {
double Area = 0;
void RectangleArea(float length, float breadth) {
Area = length * breadth;
System.out.println("Area of rectangle is: " + Area);
}
void SquareArea(float Side) {
Area = Side * Side;
System.out.println("Area of Square is: " + Area);
}
void CircleArea(float radius) {
Area = (radius * radius) * 3.14;
System.out.println("Area of Circle is: " + Area);
}
}
public class objArea
{
public static void main(String[] args) {
Area a = new Area();
a.RectangleArea(5.5f, 7f);
a.SquareArea(5f);
a.CircleArea(4);
}
}
Explanation:XD