1#include <iostream>
2
3class Entity {
4public:
5 static int x,y;
6 static void Print() {
7 std::cout << x << ", " << y << std::endl;
8 }// sta1tic methods can't access class non-static members
9};
10int Entity:: x;
11int Entity:: y;// variable x and y are just in a name space and we declared them here
12int main() {
13 Entity e;
14 Entity e1;
15 e.x = 5;
16 e.y = 6;
17 e1.x = 10;
18 e1.y = 10;
19 e.Print();//output => 10 because variable x and y being static point to same block of memory
20 e1.Print();//output => 10 because variable x and y being static point to same block of memory
21 Entity::x; //you can also acess static variables and functions like this without creating an instance
22 Entity::Print(); //you can also acess static variables and functions like this without creating an instance
23 std::cin.get();
24}