+ 1
I want to learn about static keyword plz somebody help
3 Respuestas
+ 1
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 (how would you know which instance Hello class you want to refer to?). static members can only refer to static members. Instance members can, of course access static members.
Side note: Of course, static members can access instance members through an object reference.
See http://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-a-class
+ 1
The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.
The static can be:
- variable (also known as class variable)
- method (also known as class method)
- block
- nested class
0
Some others links :
-> http://crunchify.com/java-static-methods-variables-static-block-and-class-with-example/
-> https://en.m.wikibooks.org/wiki/Java_Programming/Keywords/static
-> http://www.javatpoint.com/static-keyword-in-java
-> https://www.caveofprogramming.com/java/java-for-beginners-static-variables-what-are-they.html