answersLogoWhite

0

What is Private public and protected?

Updated: 9/17/2019
User Avatar

Wiki User

14y ago

Best Answer

They are access modifiers used in c++ under the concept of Object Oriented Programming. They're generally used within a class

  1. Public: The data members and methods having public as access specifier can be accessed by the class objects created outside the class.
  2. Protected: The data members and methods declared as protected will be accessible to the class methods and the derived class methods only.
  3. Private: These data members and methods will be accessible from the class methods only, not from derived classes and not from objects created outside the class.
User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is Private public and protected?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are different access specifiers in c sharp?

public private internal protected internal protected


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


What is public derivation in object-oriented programming?

Public derivation or public inheritance means that all the public members of the base calls are declared public in the derived class while the protected members remain protected. Protected inheritance means all the public members of the base class are declared protected in the derived class, as are the protected members. Private inheritance means all the public and protected members of the base class are declared private in the derived class. Private members of the base class are never inherited and are therefore unaffected by inheritance. Note that regardless of the type of inheritance specified, individual non-private members of the base class can be inherited with public or protected access as required of the derived class. The type of inheritance can be therefore be thought of as being the default inheritance for all base class members which can (optionally) be overridden for specific members where required.


What is public private protected variable function?

The public, protected and private keywords only apply to object oriented programming languages. They are used to determine the accessibility of specific class members and their bases. Private members are only accessible to the class and to friends of the class. Protected members are the same as private but are also accessible to derivatives of the class. Public members are accessible to all code. When applied to base classes, the public, protected and private keywords can be used to either maintain or reduce the accessibility of the base class members (but never to increase their accessibility). When declared public, the accessibility of the base class members remains as defined by the base class. When declared protected, the public members become protected members. And when declared private, all members of the base class become private members. As well as defining the overall accessibility of the base class members, the accessibility of individual base class members can also be specified.


What are the various access specifiers?

Three types of access specifier private , public ,protected


Define protected access modifire in c plus plus?

The access privileges in c++ are 1.public 2.private 3.protected and by default its private


What is the application of public protected and private keywords?

The public, protected, and private keywords are access modifiers that specify if the item they modify can be accessed inside or outside the class or a derived class.A public item is fully accessible, inside or outside the class, including inside a derived class.A protected item is accessible only inside the class or inside a derived class.A private item is accessible only inside the class.


Two types of access modifier in java?

public, <blank/none specified>, protected, private


What do you mean by protected derivation of a sub class from base class?

When you derive a class (the sub-class) from a base class using protected access, all public members of the base class become protected members of the derived class, while protected members of the base class will remain protected. Private members are never inherited so they remain private to the base class. By contrast, if you use public inheritance, the public members of the base class remain public to the derived class, while protected members of the base class remain protected in the derived class. If you use private inheritance, both the public and protected members of the base class become private to the derived class. Note that accessibility cannot be increased, only reduced or left the same. That is, a protected member of a base class cannot be inherited as a public member of a derived class -- it can only be declared private or remain protected. Note also that accessibility is viewed from outside of the derived class. That is, all members of a base class other than the private members are inherited by the derived class and are therefore fully accessible to the derived class. But from outside of the derived class, all base class accessibility is determined by the access specified by the type of inheritance.


Why you are mark a class protected for inheritance?

Public, Private and Protected "keywards/ access modifiers" are used similarly as they are with variables. Protected variables, methods or class CAN ONLY be used by an inherited class.


Why protected acess bettr than private acess?

It is neither better nor worse. There are simply cases where you would want to use protected access, in other cases private access, in other cases public access.


In c plus plus what is the purpose of the keyword public and private in the definition of a class?

Public members/functions can be accessed from outside the class, private members/functions can only be accessed from functions of that class. Ex. class sampleClass{ private int value; public void setValue(int a){value = a;} /* legal, value can be accessed since this is a method within the same class */ public int getValue(){return value;} }; int main() { sampleClass sc; // class is instantiated sc.setValue(5); // legal, setValue() is public sc.value = 7; // ERROR, value is private, will not compile printf("%d\n", sc.getValue()); // Will print 5 return 0; }