LoginSignup
1
0

More than 1 year has passed since last update.

Javaでクラスの継承を使ったコンストラクタの実験をしました

Last updated at Posted at 2021-06-13

Javaでクラスの継承を使ったメソッドの呼び出し実験をしました。

package nogizaka;
// Author 2021/06/13
// 乃木坂好きのITエンジニア

class A{
    A(){

    }
    A(String message){
        System.out.println(message + "大好き");
    }
}
class B extends A{

    B(){
        System.out.println("Hello from B");
    }
    B(String name){
        System.out.println(name);
    }
}

public class Problem6_7 {
    public static void main(String[] args) {
        //継承元のAのコンストラクタを呼び出す
        A b = new A("乃木坂46");
        //継承先のBのコンストラクタを呼び出す
        B b1 = new B();
        //継承先のBの引数付きのコンストラクタをオーバーロードする
        B a = new B("山下美月");
    }
}
1
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0