CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
Question :
What is public, protected, private?
Category C++ Interview Questions
Rating (3.9) By 10 users
Added on 10/22/2004
Views 6427
Rate it!
Answers:

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



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.



 Posted by: akanksha    

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



 Posted by: rahul    

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



 Posted by: nitya nootan sharma    

Contact nitya nootan sharma  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



 Posted by: kiran a s    

Contact kiran a s  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



 Posted by: APARNA SINGH    

Contact APARNA SINGH  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



 Posted by: jaywant topno    

Contact jaywant  topno  Contact jaywant topno


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is the difference between class and structure?
View Answer
What is friend function?
View Answer
What are virtual functions?
View Answer
What is a scope resolution operator?
View Answer
What do you mean by inheritance?
View Answer
What is polymorphism? Explain with an example?
View Answer
What is the difference between an object and a class?
View Answer
What is encapsulation?
View Answer
What is abstraction?
View Answer
What do you mean by binding of data and functions?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C++ Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/957/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

1.06