fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Person {
  8.  
  9. String name;
  10. int age;
  11.  
  12. public Person (int age, String name) {
  13. this.age = age;
  14. this.name = name;
  15. }
  16.  
  17. @Override
  18. public String toString() {
  19. return "My name is " + this.name + " and my age is " + this.age;
  20. }
  21. }
  22.  
  23. /* Name of the class has to be "Main" only if the class is public. */
  24. class Ideone
  25. {
  26. public static void main (String[] args)
  27. {
  28. Person person = new Person(25, "John");
  29. System.out.println(person);
  30. }
  31. }
  32.  
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
My name is John and my age is 25