C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 39)
39.
What will be the output of the following program?
#include<iostream.h>
class Base
{
int x, y;
public:
Base()
{
x = y = 0;
}
Base(int xx)
{
x = xx;
}
Base(int p, int q = 10)
{
x = p + q;
y = q;
}
void Display(void)
{
cout<< x << " " << y << endl;
}
}objDefault(1, 1);
class Derived: public Base
{
Base obj;
public:
Derived(int xx, int yy): Base(xx, xx + 1)
{ }
Derived(Base objB = objDefault)
{ }
};
int main()
{
Derived objD(5, 3);
Derived *ptrD = new Derived(objD);
ptrD->Display();
delete ptrD;
return 0;
}
Discussion:
4 comments Page 1 of 1.
Vivek v said:
8 months ago
This will be an overloading function, right?
Anyone, please explain it clarely.
Anyone, please explain it clarely.
BartoszT said:
6 years ago
Is it ambiguity?
Base(int xx)
Base(int p, int q = 10)
Base(int xx)
Base(int p, int q = 10)
Phong said:
1 decade ago
Derived(5:3) : Base(5,6).
x = 5 + 6 = 11.
y = 6.
x = 5 + 6 = 11.
y = 6.
Raj said:
1 decade ago
How ? Could anybody please explain ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers