Technical Interview Questions and Answers :: TCS
Tot. Mock Test: 40
Total Qs: 157+
Object is a software bundle of variables and related methods. Objects have state and behavior.
Constructor is used to initialise class variable when object of class is created
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.
Friend classes are used when two or more classes are designed to work together and need access to each others implementation in ways that the rest of the world shouldnâ€™t be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class Database Cursor to have more privilege to the internals of class Database than main () has.
Container class is a class that hold group of same or mixed objects in memory. It can be heterogeneous and homogeneous. Heterogeneous container class can hold mixed objects in memory whereas when it is holding same objects, it is called as homogeneous container class.
By using a friend function.
A friend function has access to all private and protected members of the class for which it is a friend.
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.
A friend function can access a class private data, even though it is not a member function of the class. This is useful when one function must have access to two or more unrelated classes and when an overloaded operator must use, on its left side, a value of a class other than one of which it is a member. Friends are also used to facilitate functional notation.
It is possible to grant a non-member function access to the private members of a class by using a friend. A friend function has access to all private and protected members of the class for which it is a friend.
No Discussion on this question yet!
Now Class B