This commit is contained in:
2026-10-14 17:26:07 +09:00
parent 79fb30d941
commit 77d3cbfcc6
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
public class ObjectSample {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//原本のコピー(インスタンス生成)
Student student1 = new Student();
Student student2 = new Student();
//name、ageへの代入
student1.name = "田中";
student1.age = 30;
student2.name = "山本";
student2.age = 25;
//introduceメソッドの呼び出し
student1.intoroduce();
student2.intoroduce();
}
}

View File

@@ -0,0 +1,13 @@
public class Student {
//フィールドの宣言
String name;
int age;
//メソッドの定義
public void intoroduce() {
System.out.println("私の名前は" + this.name);
System.out.println("年齢は" + this.age);
}
}