/** * ドメイン非依存URL出力フィルタ * javadrill.tech移行時はwp_options.home/siteurlのみ変更すればよい * * データベースには絶対URL(https://minner.asia)を保持し、 * 表示時に現在のドメイン(home_url())に動的変換する */ function javadrill_make_urls_dynamic($content) { if (empty($content)) { return $content; } // データベース内の絶対URLを現在のhome_url()に置換 $old_url = 'https://minner.asia'; $new_url = untrailingslashit(home_url()); // http版も対応(念のため) $content = str_replace($old_url, $new_url, $content); $content = str_replace('http://minner.asia', $new_url, $content); return $content; } // 投稿本文、ウィジェット、タームの説明、抜粋に適用 add_filter('the_content', 'javadrill_make_urls_dynamic', 20); add_filter('widget_text', 'javadrill_make_urls_dynamic', 20); add_filter('term_description', 'javadrill_make_urls_dynamic', 20); add_filter('get_the_excerpt', 'javadrill_make_urls_dynamic', 20); 018 オブジェクト指向の深化(ポリモーフィズムの応用) 010 解答例 | Javaドリル

018 オブジェクト指向の深化(ポリモーフィズムの応用) 010 解答例

018-010 018 オブジェクト指向の深化
// インターフェース Drawable
interface Drawable {
    void draw();
}

// Circle クラス
class Circle implements Drawable {
    private double radius;

    // コンストラクタ
    public Circle(double radius) {
        this.radius = radius;
    }

    // draw メソッドの実装
    @Override
    public void draw() {
        System.out.println("Drawing a circle with radius: " + radius);
        // ここに円を描画するための具体的な処理を追加
    }
}

// Rectangle クラス
class Rectangle implements Drawable {
    private double width;
    private double height;

    // コンストラクタ
    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    // draw メソッドの実装
    @Override
    public void draw() {
        System.out.println("Drawing a rectangle with width: " + width + " and height: " + height);
        // ここに長方形を描画するための具体的な処理を追加
    }
}

// Main クラス
public class Main {
    public static void main(String[] args) {
        // 異なる図形のインスタンスを生成
        Drawable circle = new Circle(5.0);
        Drawable rectangle = new Rectangle(8.0, 4.0);

        // 各図形を描画
        System.out.println("Drawing different shapes:");
        circle.draw();
        rectangle.draw();
    }
}

このプログラムでは、Drawable インターフェースを実装した Circle クラスと Rectangle クラスがあります。main メソッドでは、異なる図形のインスタンスを生成し、それぞれの draw メソッドを呼び出して図形を描画しています。

「018 オブジェクト指向の深化」問題集リスト

🎯 実習で理解を深めよう

この内容についてJavaDrillで実際に手を動かして学習できます

コメント

タイトルとURLをコピーしました