If I will create a new object like the following, which access modifier will it have by default?
Object objectA = new Object();
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.
Any member will always have the most restrictive one available – so in this case the accessibility of
objectAisprivate. (Assuming it’s an instance variable. It makes no sense as a local variable, as they don’t have any access rules as such.)So this:
is equivalent to this:
The “default to most private” means that for types, the accessibility depends on the context. This:
is equivalent to this:
… because you can’t have a private non-nested class.
There’s only one place where adding an explicit access modifier can make something more private than it is without, and that’s in property declarations: