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 Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Ideone.Person tarou = (new Ideone()).new Person("Tarou");
  13. tarou.walk(12);
  14. Ideone.Person hanako = (new Ideone()).new Person("Hanako");
  15. hanako.walk(3);
  16. }
  17.  
  18. class Person
  19. {
  20. private String name;
  21. Person(String name){
  22. this.name = name;
  23. }
  24. public void walk(int dist){
  25. System.out.println(this.name + " walked for about " + dist + " kilometers.");
  26. }
  27. }
  28.  
  29. }
  30.  
Success #stdin #stdout 0.11s 35980KB
stdin
Standard input is empty
stdout
Tarou walked for about 12 kilometers.
Hanako walked for about 3 kilometers.