Test Series - oops

Test Number 15/78

Q: Which among the following best describes the constructors?
A. A function which is called whenever an object is referenced
B. A function which is called whenever an object is created to initialize the members
C. A function which is called whenever an object is assigned to copy the values
D. A function which is called whenever an object is to be given values for members
Solution: The constructors are special type of functions which are called whenever an object is created. This is to initialize the data members of the class. The constructor allocates memory space for all the data members.
Q: Which among the following best describes destructor?
A. A function which is called just before the objects are destroyed
B. A function which is called after each reference to the object
C. A function which is called after termination of the program
D. A function which is called before calling any member function
Solution: The Destructors are special functions which are called just before an object is destroyed. This functions is responsible to free all the allocated resources to the object. Objects are destroyed whenever those go out of scope.
Q: Which among the following represents correct constructor?
A. ()classname
B. ~classname()
C. –classname()
D. classname()
Solution: The constructors must contain only the class name. The class name is followed by the blank parenthesis or we can have parameters if some values are to be passed.
Q: Which among the following is correct syntax for the destructors?
A. classname()
B. ()classname
C. ~classname()
D. -classname()
Solution: The destructor must have same name as that of the corresponding class. The class name should be preceded by the tilde symbol (~).
Q: Which among the following is true?
A. First the constructor of parent classes are called in sequence of inheritance
B. First the constructor of child classes are called in the sequence of inheritance
C. First constructor called is of the object being created
D. Constructors are called randomly
Solution: First the constructor of parent class are called. The order in which the parent class constructors are called is same in the sequence of inheritance used.
Q: What is the sequence of destructors call?
A. Same order as that of the constructors call
B. Random order
C. According to the priority
D. Revere of the order of constructor call
Solution: The destructors are called in the reverse order as that of the constructors being called. This is done to ensure that all the resources are released in sequence. That is, the derived class destructors will be called first.
Q: The destructors _____________________
A. Can have maximum one argument
B. Can’t have any argument
C. Can have more than one argument
D. Can’t have more than 3 arguments
Solution: The destructors doesn’t have any arguments. The destructors have to be called implicitly whenever an object goes out of scope. The user can’t pass argument to the implicit call.
Q: Destructor calls ________________ (C++)
A. Are only implicit
B. Are only explicit
C. Can be implicit or explicit
D. Are made at end of program only
Solution: The destructors are usually called implicitly whenever an object goes out of scope. The destructors can also be called explicitly if required. The call must be made, implicitly or explicitly.
Q: Number of destructors called are ____________
A. Always equal to number of constructors called
B. Always less than the number of constructors called
C. Always greater than the number of constructors called
D. Always less than or equal to number of constructors
Solution: Destructor will be called only to free the resources allocated for an object. The resources are allocated only the constructor for an object is called.
Q: For explicit call _________________
A. The destructor must be private
B. The destructor must be public
C. The destructor must be protected
D. The destructor must be defined outside the class
Solution: The destructor must be public for explicit calls. If it is made private or protected then it won’t be accessible outside the class. There is no restriction of definition the destructor outside the class.

You Have Score    /10