2日目の1段階目完了しました。

This commit is contained in:
s-ohasi
2026-09-18 15:16:45 +09:00
parent 0dc4c3e59c
commit 944456f149
2 changed files with 25 additions and 1 deletions

View File

@@ -4,6 +4,14 @@ public class BasicCheck1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // 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);
}
} }

View File

@@ -1,4 +1,20 @@
public class Book { 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;
}
} }