C++ Programming - Constructors and Destructors - Discussion

Discussion :: Constructors and Destructors - Programs (Q.No.2)

2. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class IndiaBix
{
    public:
    IndiaBix()
    {
        cout<< "India";
    }
    ~IndiaBix()
    {
        cout<< "Bix";
    }
};
int main()
{
    IndiaBix objBix;
    return 0; 
}

[A]. The program will print the output India.
[B]. The program will print the output Bix.
[C]. The program will print the output IndiaBix.
[D]. The program will report compile time error.

Answer: Option C

Explanation:

No answer description available for this question.

Stephen said: (Jun 7, 2013)  
Both the constructor and the destructor get executed sequentially.

D.S.Raghuram said: (Jan 18, 2014)  
As the object created it invokes the constructor and then destructor followed by it.

Velmurugan said: (Mar 12, 2014)  
In main class create object name same has constructor & destructor name. So execute automatically string.

Amit said: (Jan 4, 2015)  
main.cpp: (.text+0x62): undefined reference to 'Bix::~Bix()'.
main.cpp: (.text+0x75): undefined reference to 'Bix::~Bix()'.
collect2: error: ld returned 1 exit status.

Azizbek said: (Jun 12, 2017)  
The printed output is India.

Pratik Parmar said: (Nov 2, 2017)  
The printed output is India.

Umesh said: (Mar 31, 2018)  
I think the answer should be A.

Tejas said: (Mar 1, 2020)  
Answer should be D. In code snippet there is no use of standard namespace. Hence 'cout' is undefined for the compiler.

Swapnil Mane said: (Jun 10, 2020)  
The same name of an object because of output in IndiaBix.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.