What is a static variable in OOP?

Object Oriented Programming Questions



47 Short 36 Medium 25 Long Answer Questions Question Index

What is a static variable in OOP?

A static variable in Object Oriented Programming (OOP) is a variable that is shared by all instances of a class. It is declared using the "static" keyword and is not tied to any specific object or instance. Instead, it belongs to the class itself. This means that any changes made to a static variable will be reflected across all instances of the class. Static variables are typically used to store data that is common to all objects of a class, such as a counter or a constant value.