diff --git a/em-oop/src/Day3Check2.java b/em-oop/src/Day3Check2.java new file mode 100644 index 0000000..be3f91d --- /dev/null +++ b/em-oop/src/Day3Check2.java @@ -0,0 +1,14 @@ + +public class Day3Check2 { + + public static void main(String[] args) { + Rectangle rectangle = new Rectangle(3, 4); + rectangle.showInfo(); + Greeting jpGreeting = new JapaneseGreeting(); + System.out.println(jpGreeting.hello()); + LoudGreeting jpShout = new JapaneseGreeting(); + System.out.println(jpShout.shout()); + + } + +} diff --git a/em-oop/src/Greeting.java b/em-oop/src/Greeting.java new file mode 100644 index 0000000..57d8fb6 --- /dev/null +++ b/em-oop/src/Greeting.java @@ -0,0 +1,4 @@ + +public interface Greeting { + String hello(); +} diff --git a/em-oop/src/JapaneseGreeting.java b/em-oop/src/JapaneseGreeting.java new file mode 100644 index 0000000..46901e2 --- /dev/null +++ b/em-oop/src/JapaneseGreeting.java @@ -0,0 +1,14 @@ + +public class JapaneseGreeting implements Greeting, LoudGreeting { + + @Override + public String hello() { + return "こんにちは"; + } + + @Override + public String shout() { + return "やっほー!"; + } + +} diff --git a/em-oop/src/LoudGreeting.java b/em-oop/src/LoudGreeting.java new file mode 100644 index 0000000..ed33fef --- /dev/null +++ b/em-oop/src/LoudGreeting.java @@ -0,0 +1,4 @@ + +public interface LoudGreeting { + String shout(); +} diff --git a/em-oop/src/Rectangle.java b/em-oop/src/Rectangle.java new file mode 100644 index 0000000..e74f8e4 --- /dev/null +++ b/em-oop/src/Rectangle.java @@ -0,0 +1,18 @@ + +public class Rectangle extends Shape { + + private double width; + private double height; + + public Rectangle(double width, double height) { + super("四角形"); + this.width = width; + this.height = height; + } + + @Override + public double area() { + return width * height; + } + +} diff --git a/em-oop/src/Shape.java b/em-oop/src/Shape.java index 87647df..3d099c9 100644 --- a/em-oop/src/Shape.java +++ b/em-oop/src/Shape.java @@ -1,14 +1,12 @@ -public class Shape { +public abstract class Shape { private String name; public Shape(String name) { this.name = name; } - public double area() { - return 0.0; - } + public abstract double area(); public void showInfo() { System.out.println(this.name + "の面積は" + this.area() + "です");