static keyword inside class code example
Example 1: static inside local scope in c++
#include<iostream>
class SingleTon {
public:
static SingleTon& Get() {
static SingleTon s_Instance;
return s_Instance;
}
void Hellow() {}
};
void Increment() {
int i = 0;
i++;
std::cout << i << std::endl;
};
void IncrementStaticVar() {
static int i = 0;
i++;
std::cout << i << std::endl;
}
int main() {
Increment();
Increment();
Increment();
IncrementStaticVar();
IncrementStaticVar();
IncrementStaticVar();
IncrementStaticVar();
SingleTon::Get();
std::cin.get();
}
Example 2: static in java
static keyword is a non-access modifier. static keyword can be used with
class level variable, block, method and inner class or nested class.