fork download
  1. //車クラス
  2. class Car {
  3. //メンバ
  4. //フィールド
  5. //Carクラスの宣言(仕様)
  6. int num;
  7. double gas;
  8. String name;
  9. String color;
  10. }
  11.  
  12. class Sample1{
  13. public static void main (String[] args) {
  14. //オブジェクト作成
  15. Car car1 = new Car();
  16. Car car2 = new Car();
  17.  
  18. //フィールドに値代入
  19. car1.num=55555;
  20. car1.gas=55.5;
  21.  
  22. car2.name = "小松昌平";
  23. car2.color = "みどり";
  24.  
  25. //フィールドの値を表示
  26. //System.out.println("車のナンバーは"+ car1.num +"です");
  27. //System.out.println("ガソリン量は"+ car1.gas +"です");
  28. System.out.print("車のナンバー"+ car1.num +"の持ち主は");
  29. System.out.print(car2.name+"です。"+"車の色は"+car2.color+"です。");
  30. }
  31. }
Success #stdin #stdout 0.14s 55872KB
stdin
Standard input is empty
stdout
車のナンバー55555の持ち主は小松昌平です。車の色はみどりです。