kristofer a révisé ce gist . Aller à la révision
1 file changed, 28 insertions
InterfaceDemo.java(fichier créé)
@@ -0,0 +1,28 @@ | |||
1 | + | interface Shape { | |
2 | + | double area(); | |
3 | + | double perimeter(); | |
4 | + | } | |
5 | + | ||
6 | + | class Circle implements Shape { | |
7 | + | private double radius; | |
8 | + | ||
9 | + | public Circle(double radius) { | |
10 | + | this.radius = radius; | |
11 | + | } | |
12 | + | ||
13 | + | public double area() { | |
14 | + | return Math.PI * radius * radius; | |
15 | + | } | |
16 | + | ||
17 | + | public double perimeter() { | |
18 | + | return 2 * Math.PI * radius; | |
19 | + | } | |
20 | + | } | |
21 | + | ||
22 | + | public class InterfaceDemo { | |
23 | + | public static void main(String[] args) { | |
24 | + | Circle circle = new Circle(5.0); | |
25 | + | System.out.println("Circle Area: " + circle.area()); | |
26 | + | System.out.println("Circle Perimeter: " + circle.perimeter()); | |
27 | + | } | |
28 | + | } |
Plus récent
Plus ancien