fork download
  1. class Shape {
  2. int width, height;
  3.  
  4. Shape(int width, int height) {
  5. this.width = width;
  6. this.height = height;
  7. }
  8.  
  9. int getArea() {
  10. return width * height;
  11. }
  12. }
  13.  
  14. class Rectangle extends Shape {
  15. Rectangle(int width, int height) {
  16. super(width, height);
  17. }
  18.  
  19. int getArea() {
  20. return width * height;
  21. }
  22. }
  23.  
  24. public class Main {
  25. public static void main(String[] args) {
  26. Shape shape = new Shape(10, 20);
  27. System.out.println("Shape area: " + shape.getArea());
  28.  
  29. Rectangle rectangle = new Rectangle(10, 20);
  30. System.out.println("Rectangle area: " + rectangle.getArea());
  31. }
  32. }
  33.  
Success #stdin #stdout 0.11s 47884KB
stdin
Standard input is empty
stdout
Shape area: 200
Rectangle area: 200