A Program based on :-


(a) constructor()=used to intialize object.


(b) simple member().


#include<iostream.h>
#include<conio.h>

class comment
{
public:
comment()
{
cout<<"I Love Programming"<<endl;
}
void show()
{
cout<<"I am Programmer";
}};
void main()
{
clrscr();
comment yes;
yes.show();
getch();
}

Output:


I Love Programming
I am Programmer

			

Note :-

Constructors may be declared as inline, explicit, friend or constexpr.

A constructor can initialize an object that has been declared as const, volatile or const volatile. The object becomes const after the constructor completes.

To define a constructor in an implementation file, give it a qualified name as with any other member function: Box::Box(){...}.
Previous Next