1The static keyword in Java is used for memory management mainly. We can apply static keyword with
2variables, methods, blocks and nested classes. The static keyword belongs to the class
3 than an instance of the class.
4
5The static can be:
6
7Variable (also known as a class variable)
8Method (also known as a class method)
9Block
10Nested class
1static keyword is a non-access modifier. static keyword can be used with
2class level variable, block, method and inner class or nested class.
1static keyword: belongs to the class, also can be called through the class
2static variable: declared outside any block with static keyword
3static: runs first, only runs one time
4static member:
51. static variables
62. static methods
73. static initializer block
84. static inner class(nested class)
9static methods: methods that we can call it through the class name.
10 belongs to the class
11Ex: Webdriver driver = WebdriverFactory.getDriver();
12 ********* Static methods only accepts class member(static) ************
13********* None static can ONLY be called through the object ***********
14
15Static only accept static. Anything not static you cannot call directly.
16You can call Instance variable in Constructor.
17You cannot call instance variable in static you have to create object first.
18You can call non static (instance variable) in the instance block.
19You can call static in the instance block
20Static variable da last initialization will be final value.
21
22