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 Outer_Demo{
  9. int num;
  10. //inner class
  11. public class Inner_Demo{
  12. public void print(){
  13. System.out.println("This is an inner class");
  14. }
  15. }
  16. //Accessing he inner class from the method within
  17. void display_Inner(){
  18. Inner_Demo inner = new Inner_Demo();
  19. inner.print();
  20. }
  21. }
  22.  
  23. class Ideone
  24. {
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. // your code goes here
  28. //Instantiating the outer class
  29. //Outer_Demo outer = new Outer_Demo();
  30. //Accessing the display_Inner() method.
  31. //outer.display_Inner();
  32. Outer_Demo outer=new Outer_Demo();
  33. Outer_Demo.Inner_Demo inner=outer.new Inner_Demo();
  34. inner.print();
  35. }
  36. }
Success #stdin #stdout 0.05s 320576KB
stdin
Standard input is empty
stdout
This is an inner class