fork download
  1. class Student{
  2.  
  3. int age;
  4.  
  5. public void setAge(int age){
  6. this.age=age;
  7. }
  8.  
  9. public int getAge(){
  10. return age;
  11. }
  12.  
  13. @Override
  14. public String toString() { // Called for instance when
  15. return "Student with age " + age; // the student should be printed
  16. }
  17.  
  18. }
  19.  
  20.  
  21. class Main {
  22.  
  23. public static void main(String args[]){
  24.  
  25. Student stud= new Student();
  26. Student stud1= new Student();
  27. stud.setAge(15);
  28. int i=stud.getAge();
  29. String a=new String("Hello");
  30. System.out.println(stud);
  31. System.out.println(stud1);
  32. System.out.println(a);
  33. }
  34.  
  35. }
  36.  
Success #stdin #stdout 0.08s 213440KB
stdin
Standard input is empty
stdout
Student with age 15
Student with age 0
Hello