public class sample {
public static void main(String[] args) {
Novel nov = new Novel("ワンピース","漫画","山田一郎");
Magazine mag = new Magazine("月間ジャンプ","ああ","5日");
nov.printBook();
mag.printBook();
}
}
class Book{
protected String title,genre;
//コンストラクタ
Book(String tit,String gen){
title = tit;
genre = gen;
}
//出力メソッド
void printBook(){
System.out.println("タイトル:"+title);
System.out.println("ジャンル"+ genre);
}
}
class Novel extends Book{
//フィールド
static String writer;
//コンストラクタ
Novel(String t, String g, String w) {
super(writer, w);
title = t;
genre = g;
writer = w;
}
void printBook(){
super.printBook();
System.out.println("著者:"+ writer);
}
}
//Magazine子クラス
class Magazine extends Book{
//フィールド
private String day;
//コンストラクタ
Magazine(String t, String g, String d) {
super(d, d);
this.day =d; } void printBook(){ super.printBook(); System.out.println("発売日:"+day); } }
正しい
[実行結果]
タイトル:ワンピース
ジャンル:漫画
著者:山田一郎
タイトル:月間ジャンプ
ジャンル:ああ
発売日:5日
実際の実行結果
タイトル:大冒険
ジャンルファンタジー
タイトル:月間Java
ジャンルコンピュータ
なぜでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。