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
En esta página del sitio puede ver el video en línea Static Keyword in Java | Static Method | Static Variable | Static Block | de Duración hora minuto segunda en buena calidad , que subió el usuario Know Java 11 agosto 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 39 veces y le gustó 0 a los espectadores. Disfruta viendo!