diff --git a/em-oop/src/Day3Check2.java b/em-oop/src/Day3Check2.java new file mode 100644 index 0000000..08aa5c4 --- /dev/null +++ b/em-oop/src/Day3Check2.java @@ -0,0 +1,11 @@ + +public class Day3Check2 { + public static void main(String[] args) { + Rectangle rect = new Rectangle(3, 4); + rect.showInfo(); + + Greeting greeting = new JapaneseGreeting(); + System.out.println(greeting.hello()); + } + +} diff --git a/em-oop/src/Greeting.java b/em-oop/src/Greeting.java new file mode 100644 index 0000000..09fe171 --- /dev/null +++ b/em-oop/src/Greeting.java @@ -0,0 +1,6 @@ + +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..6d40cce --- /dev/null +++ b/em-oop/src/JapaneseGreeting.java @@ -0,0 +1,8 @@ + +public class JapaneseGreeting implements Greeting { + @Override + public String hello() { + return "こんにちは"; + } + +} diff --git a/em-oop/src/Rectangle.java b/em-oop/src/Rectangle.java new file mode 100644 index 0000000..b2f6473 --- /dev/null +++ b/em-oop/src/Rectangle.java @@ -0,0 +1,17 @@ + +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 a1fc549..6eea310 100644 --- a/em-oop/src/Shape.java +++ b/em-oop/src/Shape.java @@ -1,16 +1,15 @@ -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() + "です"); } - - + }