+ 3
Why Non static block is needed ? What's its advantages and Limitation?
3 Réponses
+ 1
Non static block is a another way of doing initiization on object creation and it actually runs before any of the constructors is executed
+ 1
Static methods are useful if you have only one instance (situation, circumstance) where you're going to use the method, and you don't need multiple copies (objects). For example, if you're writing a method that logs onto one and only one web site, downloads the weather data, and then returns the values, you could write it as static because you can hard code all the necessary data within the method and you're not going to have multiple instances or copies. You can then access the method statically using one of the following:
0
non static block can be used to initialize non static final variables and
non static block can be used to print anything before the constructors