IntroductionWorking With Static Concepts:
- Static is a keyword.
- Static can be used with variables, constructors, methods, classes.
- Instance variables will be created seperately for every object.
- Static variables will be created only once while class is loading into the memory, Hence static variables are also called as class variables
- Static variables are sharable by all the objects.
- If static variable is public, then it can be accessed directly with ClassName.StaticVariable.
- Static constructor will be executed only once, while class is loading into the memory.
- Static constructor is capable to access only static variables.
- Static methods need to be called with ClassName.MethodName()
Test t = new Test(); -----> possible
t.display(); ----->not possible
Test.print(); ----->not possible
Whenever a class contains all static methods, then it is recommended to declare the class as static. Static classes are not instantiatable means not possible to create an object. Following is the example for static variables and methods.
Comments/Suggestions are invited. Happy coding......!