/** * ドメイン非依存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); 015 ポリモーフィズム(動的な配列) 013 解答例 | Javaドリル

015 ポリモーフィズム(動的な配列) 013 解答例

015-013 015 ポリモーフィズム
class Shape {
    public void draw() {
        System.out.println("Drawing a shape");
    }
}

class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("Drawing a circle");
    }
}

class Rectangle extends Shape {
    @Override
    public void draw() {
        System.out.println("Drawing a rectangle");
    }
}

public class Main {
    public static void main(String[] args) {
        // 動的な配列の作成
        Shape[] shapes = new Shape[3];

        // Circleオブジェクトを配列に格納
        shapes[0] = new Circle();

        // Rectangleオブジェクトを配列に格納
        shapes[1] = new Rectangle();

        // Shapeオブジェクトを配列に格納
        shapes[2] = new Shape();

        // 配列からオブジェクトを取り出してdrawメソッドを呼び出す
        for (Shape shape : shapes) {
            shape.draw();
        }
    }
}

このプログラムでは、動的な配列を作成し、その中に「Circle」、 「Rectangle」、および「Shape」のオブジェクトを格納しています。 そして、forループを使用して配列からオブジェクトを取り出し、「draw」メソッドを呼び出しています。 ポリモーフィズムにより、各オブジェクトの実際のクラスに基づいて適切な「draw」メソッドが呼び出されます。

「015 ポリモーフィズム」問題集リスト

🎯 実習で理解を深めよう

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

コメント

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