1 class Shape { 2 public double perimeter = 0.0; 3 public double perimeter(){ 4 return perimeter; 5 } 6 } 7 8 class Circle extends Shape{ 9 public double r = 0.0; 10 public Circle(double r){ 11 this.r=r; 12 } 13 public double perimeter(){ 14 perimeter = 2*3.14*r*r; 15 return perimeter; 16 } 17 } 18 19 class Square extends Shape{ 20 public double l = 0.0; 21 public double w = 0.0; 22 public Square(double l,double w){ 23 this.l=l; 24 this.w=w; 25 } 26 public double perimeter(){ 27 perimeter = 2*(l+w); 28 return perimeter; 29 } 30 } 31 32 class Perimeter{ 33 public static void main(String[] args){ 34 Shape s1 = new Circle(2.2); 35 System.out.println(s1.perimeter()); 36 s1 = new Square(2,3); 37 System.out.println(s1.perimeter()); 38 System.out.println(s1.perimeter); 39 } 40 }