- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The keyword "Static" is used for defining a static method or a static property of a class. The benefit of a static method is that we do not need to create an instance or object of the class. It does not have multiple values. It will have a single static value defined during initialization.
The keyword static is similar to the const keyword. It is set at the run time when the initialization takes place and these types of variables have global presence and scope. We can use these static variables anywhere over the script.
Note − We can reassign and change the value of a static variable, unlike a const variable.
In this example, we are creating a Simple HTML page. We have added a script that has an Example Class. The class contains the static value that is initialized during Run-time and therefore used afterward in the code.
It will produce the following output in the Console.
Welcome To Tutorials Point I am a static method.
On successful execution of the above program, it will produce the following output in the Console.
staticVariable : Welcome To Tutorials Point
- How to Use Static Variables in Arduino?
- Where and how to use to static variables in android studio?
- Where and how to use static variables in Android using Kotlin?
- Static variables in Java
- Static Variables in C
- Final static variables in Java
- Differences between static and non-static variables in Java
- Static and non static blank final variables in Java
- Kotlin static methods and variables
- Class and Static Variables in C#
- Initialization of static variables in C
- Class or Static Variables in Python?