We have to calculate the area of a rectangle, a square and a circle. Create an
abstract class 'Shape' with three abstract methods namely 'RectangleArea' taking two
parameters, 'SquareArea' and 'CircleArea' taking one parameter each. The parameters of 'RectangleArea' are its length and breadth, that of 'SquareArea' is its side and that of'CircleArea' is its radius. Now create another class 'Area' containing all the three methods 'RectangleArea', 'SquareArea' and 'CircleArea' for printing the area of rectangle, square and circle respectively. Create an object of class 'Area' and call all the three methods.
Answers
Answer:
2*(2+5)
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