Table of Contents
- 1 What happens when a derived class object is created and destroyed?
- 2 When a derived class object is destroyed the destructors are called in the reverse order of the constructors?
- 3 Which function is used to perform some action when the object is to be destroyed?
- 4 What will happen on destruction when more than one object is created?
- 5 When an object of a derived class is destroyed if the base class contains a destructor what is the order of calls to the destructors?
- 6 Can we assign derived class object to base?
What happens when a derived class object is created and destroyed?
The Finalize destructor is a protected method that can be called only from the class it belongs to, or from derived classes. The system calls Finalize automatically when an object is destroyed, so you should not explicitly call Finalize from outside of a derived class’s Finalize implementation.
When a derived class object is destroyed the destructors are called in the reverse order of the constructors?
When the derived-class object is destroyed, the destructors are called in the reverse order of the constructors—first the derived-class destructor is called, then the base-class destructor is called. A class may be derived from more than one base class; such derivation is called multiple inheritance.
What will happen when a base class pointer is used to delete the derived object?
Deleting a derived class object using a pointer of base class type that has a non-virtual destructor results in undefined behavior. To correct this situation, the base class should be defined with a virtual destructor. For example, following program results in undefined behavior.
What is the problem with the legal assignment of a derived class object to a base class variable?
In general a C++ compiler will disallow the assignment of a object of a base class to a derived one as, in a sense, the derived class is a superset of the base class: i.e. it wouldn’t know how to to deal with any members that are specific to the derived class.
Which function is used to perform some action when the object is to be destroyed?
Finalize function is used to perform some action when the object is to be destroyed. Explanation: Finalize is also called garbage collector.
What will happen on destruction when more than one object is created?
2.7. Java (and JVM in particular) uses automatic garbage collection. To put it simply, whenever new objects are created, the memory is automatically allocated for them. Consequently, whenever the objects are not referenced anymore, they are destroyed and their memory is reclaimed.
What is destructor in C++ explain with example?
A destructor is a member function that is invoked automatically when the object goes out of scope or is explicitly destroyed by a call to delete . A destructor has the same name as the class, preceded by a tilde ( ~ ). For example, the destructor for class String is declared: ~String() .
When a derived class object is destroyed in what order are the destructors executed?
When an object of a derived class is created, the base class constructor is called first, followed by the constructor for the derived class. When a derived object is destroyed, its destructor is called first, followed by the destructor for the base class. C++ constructors are executed in the order of their derivation.
When an object of a derived class is destroyed if the base class contains a destructor what is the order of calls to the destructors?
A class’s destructor (whether or not you explicitly define one) automagically invokes the destructors for member objects. They are destroyed in the reverse order they appear within the declaration for the class.
Can we assign derived class object to base?
In C++, a derived class object can be assigned to a base class object, but the other way is not possible.
Which function is used to perform some action when the object is to be destroyed 1 point a finalize () B Delete () C main () d none of the mentioned?
Discussion Forum
Que. | Which function is used to perform some action when the object is to be destroyed? |
---|---|
b. | delete() |
c. | main() |
d. | none of the mentioned |
Answer:finalize() |