A.
#include<iostream.h>
#include<conio.h>
class demo
{
private:
                static int i;
public:
                static void increment()
                                {
                                i++;
                                }
                static void display()
                                {
                                cout<<"\n I = "<<i<<endl;
                                }
};
int demo::i=7;
void main()         //By Using Class
{
                clrscr();
                demo::increment();
                demo::display();
                getch();
}
/*void main()    //By Using Object
{
                clrscr();
                demo d;
                d.increment();
                d.display();
                getch();
}              */
145 A.PNG
B. 
#include<iostream.h>
#include<conio.h>
class demo
{
private:
                static int i;
                static void increment()
                                {
                                i++;
                                }
public:
                static void display()
                                {
                                increment();
                                cout<<"\n I = "<<i<<endl;
                                }
};
int demo::i=6;
/*void main()    //By Using Class
{
                clrscr();
                demo::display();
                getch();
}              */
void main()         //By Using Object
{
                clrscr();
                demo d;
                d.display();
                getch();
}
145 B.PNG
Advertisements