answersLogoWhite

0

What is public private protected variable function?

Updated: 8/16/2019
User Avatar

Wiki User

8y ago

Best Answer

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.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

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

What is the purpose of public in java programming?

Public, Protected, and Private specify what has access to a routine or variable. Public is the most generous, meaning that variable or routine can be accessed from both inside and outside that program. Protected means that the variable or routine can be accessed broadly within the program, but not from outside. private means that variable or routine is only accessible to routine it is part of.


Which is public to all access class or struct or function or variable?

The default access specifier for a class is private. The default access specifier for a struct is public. It does not matter if it is a function or a variable.


What does get mean in java and what is the function of it?

Instead of using public variables, people have a tendency to use it as private variable (They call it encapsulate) and only allow other access these variable via getters and setters. For example: class Calculator { private int a; public int getA(){ return a; } public void setA(int a){ this.a = a; } }


What kinds of access can a class member have?

Public, protected and private access members.


Can a derived class make a public base function private true or false?

True. A derived class can make a public base function private. The derived function is private, within the derived class, but public in other contexts.


What are different access specifiers in c sharp?

public private internal protected internal protected


Is it possible to access the private variable in CPP from outside the class?

Private variables can only be accessed from outside of a class by using any public function of that same class. Or this can be accomplished by using Friend functions.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }


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 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