tampurus

39 Static class and methods

May 2nd, 2022 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. class OuterClass{
  2.    
  3.      static class InnerStaticClass{
  4.         // static method
  5.         static void display(){
  6.             System.out.println("I'm staic method");
  7.         }
  8.         // non static method
  9.         static void show(){
  10.             System.out.println("I'm non staic method");
  11.         }
  12.     }
  13. }
  14. class Main{
  15.     public static void main(String[] args){
  16.         OuterClass.InnerStaticClass obj = new OuterClass.InnerStaticClass();
  17.         // calling non static method
  18.         obj.show();
  19.        
  20.         // calling staticc method
  21.         OuterClass.InnerStaticClass.display();
  22.     }
  23. }
  24. // output
  25. I'm non staic method
  26. I'm staic method
Add Comment
Please, Sign In to add comment