STATIC MEMBER FUNCTION USING C++


/*STATIC MEMBER FUNCTION*/


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

Popular posts from this blog

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE

BOOKS DETAILS USING C STRUCTURE

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE