Advertisement
zoro-10

Pr2c.java

Mar 31st, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. interface Shape {
  2.   double area();
  3.   double perimeter();
  4. }
  5.  
  6. class Circle implements Shape {
  7.  
  8.   private double radius;
  9.  
  10.   public Circle(double radius) {
  11.     this.radius = radius;
  12.   }
  13.  
  14.   @Override
  15.   public double area() {
  16.     return Math.PI * radius * radius;
  17.   }
  18.  
  19.   @Override
  20.   public double perimeter() {
  21.     return 2 * Math.PI * radius;
  22.   }
  23. }
  24.  
  25. public class Pr2c {
  26.  
  27.   public static void main(String args[]) {
  28.     Circle c = new Circle(12.0);
  29.     System.out.println("Circle Area:" + c.area());
  30.     System.out.println("Circle Perimeter:" + c.perimeter());
  31.   }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement