Advanced C++ Programming Interview Questions and Answers - 4

Question: 16

What is public, private and protected?

Public, Protected and Private are three access specifier in C++.

Public data members and member functions are accessible outside the class.

Protected data members and member functions are only available to derived classes.

Private data members and member functions can’t be accessed outside the class.

However there is an exception can be using friend classes.

Question: 17

What are the features that are provided to make a program modular?

To create a program requires self sufficient resources, the way to make a piece of code modular so that it can be handled properly. This shows the relationship between different objects or in between the same objects. Different functions have to be used to keep the code different from the data provided. Object oriented programming allows creating a modular approach to make it more abstract and create the interactions between them. The features that are being provided in object oriented programming are:

Encapsulation: it deals with the grouping of data and functions together at one place or it can be said in an object that defines the interface of their interaction and the relationship between them.

Inheritance: it deals with the relationship that exists between the parent and child classes. A child can inherit the properties of the parent and it remains helpful in creating a hierarchy in the system to keep things more modular.

Polymorphism: is a feature that deals with different values that can be used by only one function. It doesn’t have to re-create the same function again and again for different values but, it uses the same functions to call different data types.

Question: 18

What is virtual class and friend class?

Friend class are used when two or more classes are designed to work together and need access to each other’s 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 internal of class Database than main() has.

Question: 19

How would you differentiate between a pre and post increment operates while overloading?

Mentioning the keyword int as the second parameter in the post increment form of the operator++() helps distinguish between the two forms.

Related Questions