Monday 16 March 2015

Q 15) Static And Non Static Block/Method







Static Block
Non – Static Block
01)
JVM Executes the static block at
“CLASS LOADING TIME ”
JVM executes the non – static block at
“ OBJECT CREATION TIME ”
02)
Inside a static block we can only use a static variable directly but we cannot use a non static variable.
Inside a non static block we can use only non static variables.





Static Method
Non – Static Method
01)
Inside a static method we can only use a static variable directly.
Inside the non – static method we can use both static as well as non – static variables.
02)
3 ways to call Static methods
      With the class name
Eg: Test.disp1();
      Without object reference of a class
Eg: disp1();
      With object reference
Eg: t1.disp1();
1 way to call Non- static method
      With Object reference of the class
Eg : t1.disp();




1 comment:

  1. Static block in java

    Thanks for sharing this post, really this post is very simple and easy.

    ReplyDelete