• Atom Feed

    Create Atom feed for your website in minutes
  • C Code Auto Indent

    Auto indent your entire C project with a simple shell command
  • C file ops

    Can you perform insert operation using C file operations? Check this C code and C file operations concepts
  • C posix signals

    Everything on Linux Signals and Signal handling, with sample code
  • Django MVC Framework

    Setting up Python Django website on Apache Shared web hosting server
  • FTP

    FTP Unix Command with examples
  • GlusterFS

    Concepts, Installation and Performance Benchmarking Reports
  • File Append in Java

    Program to perform File Append operation in Java
  • Essential Linux Commands

    Learn the basic essential linux commands in minutes
  • Loop Device in Linux

    Create loop device in Linux
  • PostgreSQL Database

    Installation and Startup Script
  • Pthreads - POSIX Multithreading

    APIs, Concepts and Sample Programs
  • Python Ctypes Module

    Intermixing C with Python and extending Python, with sample programs
  • Socket Programming

    Socket Programming in Linux explained, with TCP and UDP examples
  • String Functions in C

    Did you know string manipulation in C is so easy?
Home CPP Interview Questions

Explain access specifiers and access control in a class definition

Access specifier in C++ classes used as access control:

Members of a class can be restricted or controlled on its access within and outside that class. This is achieved by declaring members in either of the 3 access specifiers:

Private access specifier:

All member of a class are restricted to be accessed only by members of the same class and friend function and members of friend class.

Public access specifier:

All member of a class are free to be accessed by anyone, anywhere within and outside its class.

Protected access specifier:

All member of a class are restricted to be accessed only by members of the same class and its direct or indirect derived classes and friend function and members of friend class


Beside assigning access specifier to members in a class, members of superclass will have different access specifier in a subclass depending on the access specifier used while derivation:

Public:

When base class derived publicly, public and protected members of the base class remain public and protected members of the derived class. Private members of base class are not inherited in derive class

Private:

When base class derived privately, public and protected members of the base class will become private members in derive class. Private members of base class are not inherited in derive class

Protected:

When base class derived protectedly, public and protected members of the base class will become protected members in derive class. Private members of base class are not inherited in derive class.