GeekInterview.com
Series: Subject:
Question: 107 of 270

What is public, protected, private?

Asked by: Interview Candidate | Asked on: Jun 24th, 2005
Showing Answers 1 - 3 of 3 Answers
samiksc

Answered On : Jan 25th, 2006

View all answers by samiksc

Public: Class members having this specifier are accessible from objects created outside the class

Protected: These members will be accessible from inside the class and its derived classes.

Private: These members will be available from inside the current class only.

  
Login to rate this answer.

Samik your explanation is nice.
Easy for the beginner to understand.

  
Login to rate this answer.
SHIVANI

Answered On : Sep 20th, 2011

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

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.