【若い風】javaテスト抽象クラス、継承
- abstract class Shap {//
-
- protected double width;
- protected double length;
-
- Shap(final double width, final double length) {
- this.width = width;
- this.length = length;
- }
-
- abstract double area();//
- }
-
- class Square extends Shap {
-
- Square(final double width, final double length) {
- super(width, length);
- }
-
- double area() {
- return width * length;
- }
- }
-
- class Triangle extends Shap {
-
- Triangle(final double width, final double length) {
- super(width, length);
- }
-
- double area() {
- return width*length/2;
- }
- }
-
- public class CalculateArea {
-
- public static void main(String[] args) {
-
- Square square = new Square(20,10);
- System.out.println("
:" + square.area());
-
- Triangle triangle = new Triangle(20,10);
- System.out.println("
:" + triangle.area());
-
-
-
-
- }
-
- }