C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 40)
40.
What is correct about the following program?
#include<iostream.h>
class Base
{
int x, y, z;
public:
Base()
{
x = y = z = 0;
}
Base(int xx, int yy = 'A', int zz = 'B')
{
x = xx;
y = x + yy;
z = x + y;
}
void Display(void)
{
cout<< x << " " << y << " " << z << endl;
}
};
class Derived : public Base
{
int x, y;
public:
Derived(int xx = 65, int yy = 66) : Base(xx, yy)
{
y = xx;
x = yy;
}
void Display(void)
{
cout<< x << " " << y << " ";
Display();
}
};
int main()
{
Derived objD;
objD.Display();
return 0;
}
Discussion:
21 comments Page 1 of 3.
Nishant said:
2 years ago
I think the correct answer is option E.
R Y said:
3 years ago
The Correct answer will be E.
(1)
Ayush said:
3 years ago
Option E explain the recursive call for display function()
void Display(void)
{
cout<< x << " " << y << " ";
because of this-> Display();
}
void Display(void)
{
cout<< x << " " << y << " ";
because of this-> Display();
}
Nissy said:
4 years ago
Can anyone explain why it is a recursive function?
Anonymous said:
5 years ago
It should be the E option since it is printing the 66 65 infinitely.
Venu Vangari said:
6 years ago
The program will produce the output 66 65 infinite number of times.
Sarvesh karan said:
7 years ago
I think I got the answer. Even if we are creating object with no arguments. It will invoke paremeterized constructor of derived class as it is default in its arguments.
Sarvesh karan said:
7 years ago
Why its not an error?
The derived class doesn't have a default constructor and only one parameterized constructor and default constructor cannot be invoked if the user has not specified it.
The derived class doesn't have a default constructor and only one parameterized constructor and default constructor cannot be invoked if the user has not specified it.
Akshay said:
7 years ago
E is the right option.
Dharamsingh Rajput said:
7 years ago
E is the right option according to me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers