PROGRAM TO SHOW STATIC MEMBER FUNCTION
/*WRITE A PROGRAM TO SHOW STATIC MEMBER FUNCTION*/
#include<conio.h>
#include<iostream.h>
class item
{
int code;
static int count;
public:
void setcode()
{
code=count++;
}
void showcode()
{
cout<<"\nobject number"<<code;
}
static void showcount()
{
cout<<"\ncount"<<count;
}
};
int item::count;
void main()
{
item a, b;
a.setcode();
b.setcode();
item::showcount();
item c;
c.setcode();
item::showcount();
a.showcode();
b.showcode();
c.showcode();
}
----------------------------------------------------------
OUTPUT:-
#include<conio.h>
#include<iostream.h>
class item
{
int code;
static int count;
public:
void setcode()
{
code=count++;
}
void showcode()
{
cout<<"\nobject number"<<code;
}
static void showcount()
{
cout<<"\ncount"<<count;
}
};
int item::count;
void main()
{
item a, b;
a.setcode();
b.setcode();
item::showcount();
item c;
c.setcode();
item::showcount();
a.showcode();
b.showcode();
c.showcode();
}
----------------------------------------------------------
OUTPUT:-
0 comments