1段階目(継承とsuperでシンプルな図形クラスを作ろう)

This commit is contained in:
s-sakiyama
2026-09-16 12:59:09 +09:00
parent 856eb9888a
commit 03c7af9751
3 changed files with 46 additions and 0 deletions

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

@@ -0,0 +1,22 @@
public class Circle extends Shape {
private double radius;
public Circle(double radius) {
super("円");
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius;
}
@Override
public void showInfo() {
super.showInfo();
System.out.println("(半径:" + this.radius + ")");
}
}

View File

@@ -0,0 +1,8 @@
public class Day3Check1 {
public static void main(String[] args) {
Circle circle = new Circle(2);
circle.showInfo();
}
}

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

@@ -0,0 +1,16 @@
public class Shape {
private String name;
public Shape(String name) {
this.name = name;
}
public double area() {
return 0.0;
}
public void showInfo() {
System.out.println(this.name + "の面積は" + this.area() + "です");
}
}