Static Keyword in Java | Static Method | Static Variable | Static Block |

Veröffentlicht am: 11 August 2023
auf dem Kanal: Know Java
39
0

In Java, static keyword is mainly used for need to define class members that independent any object of class. It can be used with variables, methods and blocks. It is a keyword which is used to share the same variable or method of a given class. Basically, static is used for a constant variable or a method that is same for every instance of a class. The main method of a class is generally labeled static.

In order to create a static member (block, variable, method,), you need to precede its declaration with the keyword static. When a member of the class is declared as static, it can be accessed before the objects of its class are created, and without any object reference.

Static Variables
When you declare a variable as static, then a single copy of the variable is created and divided among all objects at the class level. Static variables are, essentially, global variables. Basically, all the instances of the class share the same static variable. Static variables can be created at class-level only.

Static Method
When a method is declared with the static keyword, it is known as a static method. The most common example of a static method is the main( ) method.


Static Block
If you need to do the computation in order or block of code to initialize your static variables, you can declare a static block that gets executed exactly once, when the class is first loaded


More updates join our telegram group:-https://t.me/knowjavaprograming





Oops Playlist link:-
   • Playlist  



#JavaOOP
#JavaObjectOrientedProgramming
#JavaInheritance
#JavaPolymorphism
#JavaEncapsulation
#JavaAbstraction
#JavaClassesAndObjects
#JavaObjectCreation
#JavaConstructor
#JavaInterface


Auf dieser Seite können Sie das Online-Video Static Keyword in Java | Static Method | Static Variable | Static Block | mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Know Java 11 August 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 39 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!