Real life example
static = school ke total students ka counter. Har student ka apna nahi, sab ka ek.
Industry example
Server par active connections ka count: static counter har naye connection par badhta hai.
C++ code
class User {
static int count;
public:
User(){ count++; }
static int total(){ return count; }
};
int User::count = 0;
What happens when it runs
3 User bane User::total() = 3
Run the full program in the compiler Interactive version
Quiz
static data member ki kitni copies hoti hain?
static member class ka hota hai aur sab objects ke beech share hota hai.
Try it yourself
Write one example of const, Initializer List, static from your own home, school or work. Then change the program in the compiler and run it again.
All 12 OOP lectures
- Lecture 1: Introduction aur Objects
- Lecture 2: Encapsulation aur Interface
- Lecture 3: Abstraction, Class, Inheritance
- Lecture 4: Inheritance ke Concepts
- Lecture 5: Association, Composition, Aggregation
- Lecture 6: Polymorphism
- Lecture 7: C++ me Class
- Lecture 8: Constructor
- Lecture 9: Copy Constructor, Destructor, this
- Lecture 10: this Pointer aur const Functions
- Lecture 11: const, Initializer List, static
- Lecture 12: static Functions aur Array of Objects
START WELL TO END WELL