Question:
What is public, protected, private?
Answer:
Ø Public, protected and private are three access specifiers in C++.
Ø Public data members and member functions are accessible outside the class.
Ø Protected data members and member functions are only available to derived classes.
Ø Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes. Source: CoolInterview.com
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. Source: CoolInterview.com
Answered by: akanksha | Date:
| Contact akanksha
Ø Public, protected and private are three access specifiers in C++.
Ø Public data members and member functions are accessible outside the class.
Ø Protected data members and member functions are only available to derived classes.
Ø Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes Source: CoolInterview.com
Answered by: rahul | Date:
| Contact rahul
1. private,public,and protected are three acess specifires. 2.private data member can be accessed only in base class meanwhile public data member and member function are acessed everywhere in a entire program. 3.protected data member and member function can be accessed in drive class and base class Source: CoolInterview.com
Answered by: nitya nootan sharma | Date:
| Contact nitya nootan sharma
1.private public and protected are three in built acess specifier in c++. 2.private members and functions are accessible only by base class 3.public members and functions can be used any where in the program 4.protected data member and member function can be accessed in drive class and base class Source: CoolInterview.com
Answered by: kiran a s | Date: 5/31/2009
| Contact kiran a s
public-if member is public it can be used by any function.Mmenbers of struct and union are public by default. private-if member is private it can be used by any member function and friends of the classes in which it is declared protected-:it access is the same for private Source: CoolInterview.com
Answered by: APARNA SINGH | Date: 6/1/2009
| Contact APARNA SINGH
these all are called acess specifier.where public can acess globally in the program.where as private can acess only the same class variable and methods but not to other class. protected:where no other class can acess the data of that class ex: in a class declarition if we will not declare specifier than it takes as an public. where as for private and protected we have to write the acess specifier Source: CoolInterview.com
Answered by: jaywant topno | Date: 9/27/2009
| Contact jaywant topno
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|