2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Javaのクラス継承の検証をしました

class Kotehan1 {
	void kotehan(String t) {
		System.out.println(t);
	}

}
//Kotehan1クラスを継承してAlparajyu1クラスを作成する
class Alparajyu1 extends Kotehan1 {
	private String kotehan_name;
	void kotehan(String t) {
		this.kotehan_name = t;
		System.out.println(this.kotehan_name);
	}
	String getkotehan() {
		//System.out.println(this.kotehan_name);
		return this.kotehan_name;
	}
}

public class Alpa15 {
	public static void main(String[] name) {
		// Kotehan1インスタンスを呼び出す
		Kotehan1 kt = new Kotehan1();
		// Alparajyu1インスタンスを呼び出す
		Alparajyu1 al = new Alparajyu1();
		// Alparajyu1インスタンスをKotehan1で呼び出す
		Kotehan1 kt2 = new Alparajyu1();
		//Kotehan1のkotehanメソッドを呼び出す
		kt.kotehan("アルファラジュ");
		//Alparajyu1のkotehanメソッドを呼び出す
		al.kotehan("アルファラジュ");
		//Alparajyu1のgetkotehanメソッドを呼び出す
		String name1 = al.getkotehan();
		//リターンコードを表示
		disp(name1);
		//Alparajyu1のkotehanメソッドを呼び出し、Kotehan1クラス型に変換する
		kt2.kotehan("アルファラジュ1");

	}
	public static void disp(String s) {
		System.out.println(s);
	}
}

実行結果は下記の画像になります

結果.jpg

2
1
3

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?