fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. Dog ta = new Dog(10.5, 0.8, "taro");
  4. ta.bark();
  5. ta.eat();
  6. ta.bark();
  7. }
  8. }
  9.  
  10. class Dog {
  11. public double weight; // インスタンス変数
  12. public double height; // インスタンス変数
  13. public String name; // インスタンス変数
  14.  
  15. // コンストラクタ(クラス名と同じ名前・戻り値の型なし)
  16. public Dog(double w, double h, String n) {
  17. weight = w;
  18. height = h;
  19. name = n;
  20. }
  21.  
  22. public void eat() {
  23. weight += 0.1;
  24. }
  25.  
  26. public void bark() {
  27. System.out.println("名前:" + name + " 体重:" + weight + " 体高:" + height);
  28. }
  29. }
Success #stdin #stdout 0.15s 46016KB
stdin
Standard input is empty
stdout
名前:taro 体重:10.5 体高:0.8
名前:taro 体重:10.6 体高:0.8