Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview.
31) What is a constructor? Why would I ever use one?
Answer: A constructor is a member function with the same name as that of its class. Constructors are automatically invoked when an object of the same class is created. The constructor has the same name as that of the class.
A constructor is used often to initialize the objects of that class type with a legal initial value.
32) What are destructors really for? Why would I ever use them?
Answer: A destructor is a member function with the same name as that of its class but is preceded by a tilde (~). Destructors are really for the purpose of de-initializing an object before it goes out of scope.
33) Is a default constructor equivalent to a constructor having default arguments?
Answer: Yes, a default constructors is equivalent to a constructor having default arguments because when no initial values are provided for an object at the time of its declaration, the constructor having default argument values is invoked same way as the default constructor is invoked. Therefore, these two are considered equivalent.
34) Why is a destructor function required in a class?
Answer: During construction of an object by a constructor, resources are allocated for use. These resources must be de-allocated before the object is destroyed. A destructor achieves this function and performs all clean-up jobs.
35) What is a parameterized constructor?
Answer: A constructor that receives arguments or parameters is called a parameterized constructor.
ALSO READ:
Frequently Asked C++/OOPS Interview Questions With Answers – 8.
Frequently Asked C++/OOPS Interview Questions With Answers – 9.
Frequently Asked C++/OOPS Interview Questions With Answers – 10.
Frequently Asked C++/OOPS Interview Questions With Answers – 11.
… Back To C++/OOPS Interview QnA Index.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com