Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are the differences between public, private, and
protected access?

Answer Posted / swetcha

We use these keywords to specify access levels for member
variables, or for member functions (methods).

.Public variables, are variables that are visible to all
classes.

.Private variables, are variables that are visible only to
the class to which they belong.

.Protected variables, are variables that are visible only
to the class to which they belong, and any subclasses.


Deciding when to use private, protected, or public
variables is sometimes tricky. You need to think whether or
not an external object (or program), actually needs direct
access to the information. If you do want other objects to
access internal data, but wish to control it, you would
make it either private or protected, but provide functions
which can manipulate the data in a controlled way.

Is This Answer Correct ?    172 Yes 22 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is upcasting in C++?

1236


Is c++ still in demand?

1200


What is a dangling pointer in c++?

1205


What is endl c++?

1154


If you want to share several functions or variables in several files maitaining the consistency how would you share it?

1052


Tell me an example where stacks are useful?

1099


Differentiate between realloc() and free().

1102


What is c++ flowchart?

1460


Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

1135


Program to check whether a word is a sub-string or not of a string typed

2085


Difference between overloading vs. Overriding

1138


Is c++ used anymore?

1137


Does a derived class inherit or doesn't inherit?

1126


Define basic type of variable used for a different condition in C++?

1193


What is an inclusion guard?

1285