C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : 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; 
}
The program will print the output India.
The program will print the output Bix.
The program will print the output IndiaBix.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
9 comments Page 1 of 1.

Swapnil Mane said:   5 years ago
The same name of an object because of output in IndiaBix.

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

Umesh said:   8 years ago
I think the answer should be A.

Pratik Parmar said:   8 years ago
The printed output is India.

Azizbek said:   8 years ago
The printed output is India.

Amit said:   1 decade ago
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.

Velmurugan said:   1 decade ago
In main class create object name same has constructor & destructor name. So execute automatically string.

D.S.RAGHURAM said:   1 decade ago
As the object created it invokes the constructor and then destructor followed by it.

Stephen said:   1 decade ago
Both the constructor and the destructor get executed sequentially.

Post your comments here:

Your comments will be displayed after verification.