diff --git a/em-oop/src/Circle.java b/em-oop/src/Circle.java new file mode 100644 index 0000000..9097f3b --- /dev/null +++ b/em-oop/src/Circle.java @@ -0,0 +1,25 @@ + +public class Circle extends Shape { + + //Shapeクラスを継承 + + //フィールド作成 + private double radius; + + //コンストラクタ作成 + public Circle(double radius) { + super("円"); + this.radius = radius; + } + + //メソッド作成 + public double area() { + return Math.PI * radius * radius; + } + + public void showInfo() { + super.showInfo(); + System.out.println("(半径:" + this.radius + ")"); + } + +} diff --git a/em-oop/src/Day3Check1.java b/em-oop/src/Day3Check1.java new file mode 100644 index 0000000..814f6a7 --- /dev/null +++ b/em-oop/src/Day3Check1.java @@ -0,0 +1,15 @@ + +public class Day3Check1 { + + public static void main(String[] args) { + + //インスタンス作成 + Circle c = new Circle(2); + + //メソッド呼び出し + c.showInfo(); + + + } + +} diff --git a/em-oop/src/Shape.java b/em-oop/src/Shape.java new file mode 100644 index 0000000..29a87d1 --- /dev/null +++ b/em-oop/src/Shape.java @@ -0,0 +1,22 @@ + +public class Shape { + + //フィールド作成 + private String name; + + //コンストラクタ作成 + public Shape(String name) { + } + + //メソッド作成 + double area() { + return 0.0; + } + + //メソッド作成 + void showInfo() { + //出力 + System.out.println(this.name + "の面積は" + this.area() + "です"); + } + +}