unlike non static members,objects don't have distinct copy of these members.they are used when you actually
want to define some kind of functionality in a class that will remain equal for all objects of the class in which it
is declared.for ex-suppose you need to count every time a instance of a class is instantiated,you can achieve it
via this by declaring a static variable and increment it each time in a constructor when it is instantiated.they are
also used to define a constant by using a final keyword along with it.static members are accessed via class name
rather than an object.
you can have a static -->
2.static nested class
4.static block-they are actually used generally for changing default values of a static variable and are executed when
class will load in JVM.
please see this link for static blocks.
and this one,oracle tutorial,for other static members.
Hope this will help!
I think you mean static initialisers. They are not easy to understand, and they can cause problems if there are multiple initialisers because multiple initialisers run in a certain order whereas fields are not ordered. They are used for initialising fields, and a single static initialiser is sometimes the best way to initialise your static fields. You can read about them in the Java® Language Specification (=JLS). That part of the JLS is quite easy to understand, unlike this part which tells you that static initialsiers are not members of the class.
praveen kumaar wrote:. . .static block-they are actually used generally for changing default values of a static variable and are executed when class will load in JVM. . . .
i don't get you?
arshi Bano wrote:We can characterize class individuals static utilizing static catchphrase. When we pronounce an individual from a class as static it implies regardless of what number of objects of the class are made, there is one and only duplicate of the static part.
can you please elaborate your words(in the last post).
Campbell Ritchie wrote:I think you mean static initialisers.
yeah i mean the same,"static initializers".