C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - Programs (Q.No. 11)
11.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix(short ss)
{
cout<< "Short" << endl;
}
IndiaBix(int xx)
{
cout<< "Int" << endl;
}
IndiaBix(char ch)
{
cout<< "Char" << endl;
}
~IndiaBix()
{
cout<< "Final";
}
};
int main()
{
IndiaBix *ptr = new IndiaBix('B');
return 0;
}
Discussion:
9 comments Page 1 of 1.
Deep yadav said:
6 years ago
Refer question no 11 and 12 both are same question then how output is different.
Ajay kumar said:
8 years ago
IndiaBix *ptr = new IndiaBix('B');
In the above syntax input is 'B'.
It is default input and it will search first for the same match it will match from,
IndiaBix(char ch),
{
cout<< "Char" << endl;
}
So, it will display output is char.
In the above syntax input is 'B'.
It is default input and it will search first for the same match it will match from,
IndiaBix(char ch),
{
cout<< "Char" << endl;
}
So, it will display output is char.
Amit said:
1 decade ago
As constructor is getting overloaded, and the parameter is ('B') i.e hence char will be printed, as we have not created obj hence destructor will not be called.
Pratendra said:
1 decade ago
When I run this pgm in Turbo C it shows the output is Option C.
DIpen said:
1 decade ago
As the constructor is given an char data type as in argument, so it would be overloaded.
Karthick said:
1 decade ago
When i run this pgm in Turbo C it shows the output is Option C.
Prabha said:
1 decade ago
The destructor is not being called here implicitly because we have not created an object. We have created a pointer, so it has to be called explicitly.
Shanu said:
1 decade ago
Shruti@ yeah you are right.
Shruti said:
1 decade ago
I have checked it out.Indiabix() is an overloaded function here and will select 'char '.
destructor has to be called explicitly because it has been defined.calling would be ptr->~IndiaBix();
destructor has to be called explicitly because it has been defined.calling would be ptr->~IndiaBix();
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers