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.
Auf dieser Seite können Sie das Online-Video Learn Java Tutorial 14 Static function with example mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Champion Mahipal 30 Juni 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 168 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!