Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. public abstract class Shape {
  2.     //protected int x, y;
  3.  
  4.     public String color;
  5.     public abstract double computeArea( );
  6. }
  7.  
  8. ------------------
  9.  
  10.  
  11.  
  12. public class Rectangle extends Shape {
  13.  
  14.     double width, height;
  15.  
  16.     public Rectangle(double width, double height, String color) {
  17.         this.width = width;
  18.         this.height = height;
  19.         super.color = color; <-------------------------------------
  20.  
  21.     }
  22.  
  23.     public double computeArea( ) {
  24.         return width * height;
  25.     }
  26. }
  27.  
  28. ------------
  29.  
  30.  
  31. public class Circle extends Shape {
  32.     double radius;
  33.  
  34.  
  35.     public Circle(double radius) {
  36.         this.radius = radius;
  37.     }
  38.  
  39.     public double computeArea( ) {
  40.         return Math.PI * radius * radius;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement