What are public, private and protected in object oriented programming?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are access modifiers and help us implement Encapsulation (or information hiding). They tell the compiler which other classes should have access to the field or method being defined.
private– Only the current class will have access to the field or method.protected– Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method.public– Any class can refer to the field or call the method.This assumes these keywords are used as part of a field or method declaration within a class definition.