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

Опубликовано: 11 Август 2023
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн Static Keyword in Java | Static Method | Static Variable | Static Block | длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Know Java 11 Август 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 39 раз и оно понравилось 0 зрителям. Приятного просмотра!