How data abstraction is achieved in CPP?
What will happen if you forget to implement the virtual function in the derived class?
Is the destructor is part of the program interface? If you forget to define a destructor what will happen? and why should we need to define the destructor in a class?
Data Abstraction/Hiding means hiding out the necessacy details along with emphasizing in the simpler portion. CPP originally known as C++, achieves data abstraction with the help of a class(a user defined abstract data type). The data members declared within the private section of the class are not accessible outside the world.
A derived class can replace execution provided by the base class, this function is provided to the derived class by the Virtual Function. When the derived class is not overrided by virtual function than that derived class becomes abstract.
A special member function which is called only when the object's lifetime ends, this member function is called a destructor. The destructor sets free the resources of an object that may have been acquired by the object during its execution or lifetime.
A class cannot be defined without a destructor. Either we have to declare our own destructor, or the compiler defines one for implicitly.
Purpose of a destructor is to deallocate memory along with cleaning-up a class object and its class members when the object gets destroyed. A destructor is called for a class object when that object is explicitly deleted or it passes out of scope.
Get Answers For Free
Most questions answered within 1 hours.