Monday, 19 April 2021

Class and Object

 #include<iostream.h>

#include<conio.h>


class First

{

int a;


}f4,f5;

First f2;

class First f3;

int main()

{

clrscr();

class First f;

First f1;

cout<<sizeof(f);

getch();

return 0;

};




#include<iostream.h>

#include<conio.h>

class First

{

// public:

// int a=5;

  int a;

  public:

  void show();        //member function prototype

  void display()     //Implicit

  {

   a=10;

   cout<<"In display a="<<a<<endl;

  }

};

void First :: show()            //Explicit

{

a=5;

cout<<endl<<a<<endl;

}

int main()

{

clrscr();

First f;

f.show();

f.display();

getch();

return 0;


}




#include<iostream.h>

#include<conio.h>

class First

{

public:

   First()

   {

   }

   First(int a){};

   First(int a,int b)

   {}

};

int main()

{

clrscr();

First f1;

First f=First();


First f2(5);           //Implicit

First f3=First(8);     //Explicit


First f4(6,7);

First f5=First(8,9);

getch();

return 0;


}

No comments:

Post a Comment