第一段階完了しました。

This commit is contained in:
s-ohasi
2026-09-16 16:35:38 +09:00
parent 542af2a5d4
commit 48af3a3a99
3 changed files with 62 additions and 0 deletions

25
em-oop/src/Circle.java Normal file
View File

@@ -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 + ")");
}
}

View File

@@ -0,0 +1,15 @@
public class Day3Check1 {
public static void main(String[] args) {
//インスタンス作成
Circle c = new Circle(2);
//メソッド呼び出し
c.showInfo();
}
}

22
em-oop/src/Shape.java Normal file
View File

@@ -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() + "です");
}
}