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 Student
  9. {
  10. String name;
  11. String course;
  12. int age;
  13. void displayInfo ()
  14. {
  15. System.out.println ("Student Information");
  16. System.out.println ("Name: "+name);
  17. System.out.println ("Course: "+course);
  18. System.out.println ("Age: "+age);
  19. }
  20. }
  21. class Student_Info
  22. {
  23. public static void main (String args[])
  24. {
  25. Student stud1 = new Student();
  26. // assigning values to the objects
  27. stud1.name = "Ravi";
  28. stud1.course = "Java";
  29. stud1.age = 23;
  30. stud1.displayInfo();
  31. }
  32. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
Student Information
Name: Ravi
Course: Java
Age: 23