fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Dog {
  9. double weight;
  10. double height;
  11. String name;
  12.  
  13. public Dog(double w, double h, String n) {
  14. weight = w;
  15. height = h;
  16. name = n;
  17. }
  18.  
  19. public void eat() {
  20. weight += 0.1;
  21. }
  22.  
  23. public void bark() {
  24. System.out.println("名前: " + name + ", 体重: " + weight + ", 身長: " + height);
  25. }
  26. }
  27.  
  28. class Ideone {
  29. public static void main(String[] args) {
  30. Dog ta = new Dog(10.5, 0.8, "taro");
  31. ta.bark();
  32. ta.eat();
  33. ta.bark();
  34. }
  35. }
Success #stdin #stdout 0.14s 45996KB
stdin
Standard input is empty
stdout
名前: taro, 体重: 10.5, 身長: 0.8
名前: taro, 体重: 10.6, 身長: 0.8