What is private, protected and public access specifier in cpp, explain with example?

All QuestionsCategory: Cpp LanguageWhat is private, protected and public access specifier in cpp, explain with example?
Chetan Shidling Staff asked 5 years ago

I need short information.

1 Answers
Chetan Shidling Staff answered 5 years ago

class chetan
{
     private:
      ……
     protected:
      ……
      public:
      ……
};
 

  1. The private access specifier is only visible to member functions within its class.
  2. The protected access specifier is only visible to member functions of its own and derived class.
  3. The public access specifier is only visible to all functions in the program.