A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ program to demonstrate example of Constructor Overloading
Q:

C++ program to demonstrate example of Constructor Overloading

0

C++ program to demonstrate example of Constructor Overloading

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Constructor Overloading program in C++.

/*C++ program to demonstrate example of Constructor Overloading.*/
#include <iostream>
using namespace std;
 
//Class declaration.
class Demo
{
    //Private block to declare data member( X,Y ) of integer type.
    private:
        int X;
        int Y;
 
    //Public blocks of member function to access data members.
    public:
        //Declaration of default constructor to initialize data members.
            Demo (); 
 
        //Declaration of parameterized constructor to initialize data members.
            Demo (int a, int b); 
        //To display output onn screen.
        void    Display();
     
};//End of class
 
//Definition of parameterized constructor.
Demo:: Demo()
{
    X = 10;
    Y = 20;
}
 
//Definition of parameterized constructor.
Demo:: Demo(int a, int b)
{
    X = a;
    Y = b;
}
 
 
//Definition of Display() member function.
void Demo:: Display()
{
    cout << endl << "X: " << X;
    cout << endl << "Y: " << Y << endl;
}
 
int main()
{
    Demo d1;
    cout << "Default Constructor: " << endl;
    cout << "Value after initialization : " ;
    d1.Display();   
 
    Demo d2(30,40) ; //Ctor automatically call when object is created.
    cout << "Parameterized Constructor: " << endl;
    cout << "Value after initialization : " ;
    d2.Display();   
 
    return 0;
}

Output

    Default Constructor: 
    Value after initialization: 
    X: 10
    Y: 20
    Parameterized Constructor: 
    Value after initialization: 
    X: 30
    Y: 40

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now