Learn Java Tutorial 14 Static function with example

Pubblicato il: 30 giugno 2015
sul canale di: Champion Mahipal
168
1

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.


In questa pagina del sito puoi guardare il video online Learn Java Tutorial 14 Static function with example della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Champion Mahipal 30 giugno 2015, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 168 volte e gli è piaciuto 1 spettatori. Buona visione!