This tutorial is made for learning about the Static function with example of Java Programming Language.
Java static keyword
Static variable
Program of counter without static variable
Program of counter with static variable
Static method
Restrictions for static method
Why main method is static ?
Static block
Can we execute a program without main method ?
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
1) Java static variable
If you declare any variable as static, it is known static variable.
The static variable can be used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.
The static variable gets memory only once in class area at the time of class loading.
static method
It is a method which belongs to the class and not to the object(instance)
A static method can access only static data. It can not access non-static data (instance variables)
A static method can call only other static methods and can not call a non-static method from it.
A static method can be accessed directly by the class name and doesn’t need any object
static block
The static block, is a block of statement inside a Java class that will be executed when a class is first loaded in to the JVM.
Nesta página do site você pode assistir ao vídeo on-line Learn Java Tutorial 14 Static function with example duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Champion Mahipal 30 Junho 2015, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 168 vezes e gostou 1 espectadores. Boa visualização!