Technical Interview Questions and Answers :: C++
Classes are user defined data types and behave like the built-in type of a programming language. The wrapping up of data and functions into a single unit called class.
Objects are the basic run-time entities in an object-oriented system. When a program is executed, the objects interact by sending messages to one another.
Yes, struct is similar to class, only all attributes/methods are public by default in the struct. You can very well have methods and attributes in a struct. You can also inherit from a struct (default inheritance is public).
Yes, Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses.
Protected access specifier makes the method accessible only by the derived class.
Mutable storage class is applicable to only class data members. If a data member of a class is declared as mutable, then it can be modified by an object which is declared as constant.
An array is a contiguous chunk of memory with a fixed size whereas a list is typically implemented as individual elements linked to each other via pointers and does not have a fixed size. Once an array is initialized, it cannot be resized, and it uses a fixed amount of memory regardless of how much stuff you put in it. Since a list is a collection of individual chunks of memory that are dynamically allocated, the space required to store a list is directly related to the number of elements in it.
When a method is declared as abstract/virtual method in a base class and which is overridden in a base class. If we create a variable of a type of a base class and assign an object of a derived class to it, it will be decided at a run time, which implementation of a method is to be called.
This is known as Pure-Polymorphism or Late-Binding.
The member functions of every object have access to a sort magic pointer named this, which points to the object itself. Thus any member function can find out the address of the object of which is a member.