If we use a private data member in a public class. can this class declared public can be accessed from outside?
Regarding private/public classes
Yes, the class being public can be accessed from everywhere. It can be accessed from within the class, outside the class, within the package and outside the package.
But, the private data members of the class cannot be accessed from anywhere outside the class. These data members are accessible only within the class. It cannot be accessed from outside the class. We use the getter and setter method to access the private variables from outside the class.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.