+ 3

Why Non static block is needed ? What's its advantages and Limitation?

21st Jun 2017, 9:07 AM
ÃrShåD KHãÑ
ÃrShåD KHãÑ - avatar
3 Antworten
+ 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
23rd Jun 2017, 5:55 AM
Kürti Szabolcs
Kürti Szabolcs - avatar
+ 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:
24th Jun 2017, 8:06 AM
Satwik Dondapati
Satwik Dondapati - avatar
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
23rd Jun 2017, 1:08 PM
Diwakar Bharshiv
Diwakar Bharshiv - avatar