Friday, 26 January 2018

Write a program to overload constructor. C++ GTU

#include<iostream>
using namespace std;

class test
{
    int x,y;
    public:
            test()
            {
                x=100;
                y=200;
            }
            test(int a,int b)
            {
                x=a;
                y=b;
            }
            void display()
            {
                cout<<"\nX is:"<<x<<"\nY is: "<<y;
            }
           
};
int main()
{
    test ob1(10,20);
    test ob2;
    ob1.display();
    ob2.display();
    return 0;
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...