Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Shape {
- abstract void areaOfRect(int x, int y);
- abstract void areaOfCircle(double r);
- abstract void areaOfSquare(int x);
- }
- class Rectangle extends Shape {
- void areaOfRect(int x, int y) {
- System.out.println("Area of Rectangle: " + (x * y));
- }
- void areaOfCircle(double r){}
- void areaOfSquare(int x) {}
- }
- class Circle extends Shape {
- void areaOfRect(int x, int y){}
- void areaOfCircle(double r) {
- System.out.println("Area of Circle: " + (Math.PI * r * r));
- }
- void areaOfSquare(int x) {}
- }
- // Concrete class Square extending Shape
- class Square extends Shape {
- void areaOfRect(int x, int y) {}
- void areaOfCircle(double r) {}
- void areaOfSquare(int x) {
- System.out.println("Area of Square: " + (x * x));
- }
- }
- public class ShapeDemo {
- public static void main(String[] args) {
- Rectangle rectangle = new Rectangle();
- Circle circle = new Circle();
- Square square = new Square();
- rectangle.areaOfRect(5, 10);
- circle.areaOfCircle(3.5);
- square.areaOfSquare(4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement