Saturday, November 12, 2011

// Simple constructor2
#include<iostream>
#include<conio.h>



using namespace std;

class  A{
int a;
public:
void geta(){
cout <<"Enter no.";
cin >>a;
}
void showa(){
cout<<"A="<<a;
}

A(){        //Defult constructor
a=0;
}
A (int x){    // Parameterized constructor
a=x;
}
};

main(){
A obj;// At the time of object creating constructor
        // will called automatically
        obj.showa();
        A obj2(10);    // Parameterized constructor will call
        cout<<endl;
        obj2.showa();
getch();
return 0;
}

No comments:

Post a Comment