0
What is the use of static keyword ?
4 Respuestas
+ 12
Static members belong to the class instead of a specific instance.
It means that only one instance of a static field exists even if you create a million instances of the class or you don't create any. It will be shared by all instances.
Since static methods also do not belong to a specific instance, they can't refer to instance members.
+ 1
once declared used throughout the program...
initialized as 0...
can access via static member function....
0
Static methods and variables are shared across all the instances of a class. If you change the value of a static variable it'll be changed throughout the application. Static members can be accessed without creating any instance of the class. Static methods cannot access any instance members.
Static blocks are used to execute some code only once when that particular class is loaded by the jvm (classloader).
0
Static in its most basic terms means that it's shared across the class and when it's changed everything that uses it sees the change.