+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

C++ Access Control Interview Questions and Answers

1
Difference between struct and class in terms of Access Modifier

All members of a class are private by default, whereas fields of a struct are public. Default access of a base class is private for classes and public for structures.

For Example
struct Emp {
char Name[20]; // Here Name variable is public
};

2
Explain access specifier private?

It is default one and can be access from class member of the same class.

3
What is private, public and protected Inheritance?

Private Inheritance
The Public and protected members of Base class become private members of the derived class.

Public Inheritance
All the public members and protected members are inherited as public and protected respectively.

Protected Inheritance
Public and Protected members are derived as protected members.

4
Explain access specifier protected?

The protected members can be access from member functions of the same class or friend classes or from the members of their immediate derived class.

5
What is the default access level?

The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and its sub- classes. Public members of a class can be accessed by anyone.

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US