Day2第一段階完了
This commit is contained in:
@@ -2,15 +2,22 @@
|
|||||||
public class BasicCheck1 {
|
public class BasicCheck1 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Book book = new Book();
|
//Book book = new Book();
|
||||||
|
|
||||||
book.title = "吾輩は猫である";
|
//book.title = "吾輩は猫である";
|
||||||
book.author = "夏目漱石";
|
//book.author = "夏目漱石";
|
||||||
book.price = 800;
|
//book.price = 800;
|
||||||
|
|
||||||
|
//System.out.println(book.title);
|
||||||
|
//System.out.println(book.author);
|
||||||
|
//System.out.println(book.price);
|
||||||
|
|
||||||
|
//引数なし
|
||||||
|
Book book1 = new Book();
|
||||||
|
|
||||||
|
//引数あり
|
||||||
|
Book book2 = new Book("銀河鉄道の夜", "宮沢賢治", 500);
|
||||||
|
|
||||||
System.out.println(book.title);
|
|
||||||
System.out.println(book.author);
|
|
||||||
System.out.println(book.price);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,19 @@ public class Book {
|
|||||||
String title;
|
String title;
|
||||||
String author;
|
String author;
|
||||||
int price;
|
int price;
|
||||||
|
|
||||||
|
//コンストラクタ生成
|
||||||
|
public Book() {
|
||||||
|
System.out.println( "タイトル未設定");
|
||||||
|
System.out.println( "著者未設定");
|
||||||
|
System.out.println( "0");
|
||||||
|
}
|
||||||
|
//3つの引数を持つコンストラクタ生成
|
||||||
|
public Book(String title, String author, int price) {
|
||||||
|
System.out.println(this.title = title);
|
||||||
|
System.out.println(this.author = author);
|
||||||
|
System.out.println(this.price = price);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user