STATIC MEMBER FUNCTION USING C++
PROGRAM:
#include<iostream.h>
#include<conio.h>
class sample
{
private:
static int count;
public:
sample();
static void display();
};
int sample::count=0;
sample::sample()
{
++count;
}
void sample::display()
{
cout<<"\n Counter value="<<count<<endl;
}
void main()
{
clrscr();
cout<<"\n\t STATIC MEMBER FUNCTION";
cout<<"\n\t ___________________________";
cout<<"\n Before object creation"<<endl;
sample::display();
sample a1,a2,a3,a4;
cout<<"\n After object creation"<<endl;
sample::display();
getch();
}
OUTPUT:
STATIC MEMBER FUNCTION
___________________________
Before object creation
Counter value=0
After object creation
Counter value=4
Comments
Post a Comment