Friday, 20 January 2012

Simple object creation example of C++ Language

#include<iostream>
#include<conio.h>
using namespace std;
class cons{
      private:
              int a,b;
      public:
            cons(){
             cout<<"This is constructor which is automtically called\n";
             a=b=50;
             }
             cons(int x, int y){
             cout<<"Value of X is"<<x<<endl;        
             cout<<"Value of Y is "<<y<<endl;        
             }
             void get(){
             cout<<"Value of A is "<<a<<endl;
             cout<<"Value of B is "<<b;    
             }
                    };
int main(){
    cons c(10,20),d;
    d.get();
    getch();
    return 0;
    }

No comments:

Post a Comment