Book クラスã®å®£è¨€:
public class Book {
// タイトルã¨è‘—è€…ã‚’ä¿æŒã™ã‚‹ãƒ•ィールドã®å®£è¨€
private String title;
private String author;
// コンストラクタã®å®šç¾©
public Book(String title, String author) {
this.title = title;
this.author = author;
}
// displayInfo メソッドã®å®šç¾©
public void displayInfo() {
System.out.println("Title: " + title);
System.out.println("Author: " + author);
}
}
Main クラス㧠Book オブジェクトを生æˆã—ã¦è¡¨ç¤º:
public class Main {
public static void main(String[] args) {
// Book クラスã®ã‚ªãƒ–ジェクトを生æˆã—ã¦åˆæœŸåŒ–
Book book = new Book("The Great Gatsby", "F. Scott Fitzgerald");
// ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®æƒ…å ±ã‚’è¡¨ç¤º
book.displayInfo();
}
}
ã“ã®ã‚³ãƒ¼ãƒ‰ã§ã¯ã€Book クラスãŒã‚¿ã‚¤ãƒˆãƒ«ã¨è‘—è€…ã‚’ä¿æŒã™ã‚‹ã‚ˆã†ã«å®£è¨€ã•れã¦ã„ã¾ã™ã€‚ãã—ã¦ã€Main クラスã§ã¯ Book クラスã®ã‚ªãƒ–ジェクトを生æˆã—ã€ãã®æƒ…å ±ã‚’ displayInfo() メソッドを呼ã³å‡ºã—ã¦ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã«è¡¨ç¤ºã—ã¦ã„ã¾ã™ã€‚
「007 クラスã€å•題集リスト
🎯 実習ã§ç†è§£ã‚’æ·±ã‚よã†
ã“ã®å†…容ã«ã¤ã„ã¦JavaDrillã§å®Ÿéš›ã«æ‰‹ã‚’å‹•ã‹ã—ã¦å¦ç¿’ã§ãã¾ã™


コメント