2日目の1段階目完了しました。
This commit is contained in:
@@ -4,6 +4,14 @@ public class BasicCheck1 {
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
Book book1 = new Book();
|
||||
System.out.println(book1.title);
|
||||
System.out.println(book1.author);
|
||||
System.out.println(book1.price);
|
||||
|
||||
Book book2 = new Book("銀河鉄道の夜", "宮沢賢治", 500);
|
||||
System.out.println(book2.title);
|
||||
System.out.println(book2.author);
|
||||
System.out.println(book2.price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
|
||||
public class Book {
|
||||
public String title;
|
||||
public String author;
|
||||
public int price;
|
||||
|
||||
//引数なしコンストラクタ
|
||||
public Book() {
|
||||
title = "タイトル未設定";
|
||||
author = "著者未定";
|
||||
price = 0;
|
||||
}
|
||||
//3つの引数を持つコンストラクタ
|
||||
public Book(String title, String author, int price) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user