3日目段階2です

This commit is contained in:
2026-09-16 17:07:23 +09:00
parent bafd218505
commit 90ac263e9c
5 changed files with 49 additions and 6 deletions

View File

@@ -0,0 +1,13 @@
public class Day3Check2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Rectangle Rectangle = new Rectangle(3, 4);
Rectangle.showInfo();
Greeting greeting = new JapaneseGreeting();
System.out.println(greeting.hello());
}
}

4
em-oop/src/Greeting.java Normal file
View File

@@ -0,0 +1,4 @@
public interface Greeting {
String hello();
}

View File

@@ -0,0 +1,10 @@
public class JapaneseGreeting implements Greeting {
@Override
public String hello() {
// TODO 自動生成されたメソッド・スタブ
return "こんにちは";
}
}

18
em-oop/src/Rectangle.java Normal file
View File

@@ -0,0 +1,18 @@
public class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width, double height) {
super("四角形");
this.height = height;
this.width = width;
}
@Override
public double area() {
return width * height;
}
}

View File

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