I have a question about public and private classes in Java. For example, if you have a public method inside of a private class, can the public method by accessed by other public/private classes? Thanks in advance.
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.
In order to be able to invoke a method inside a class, the method that does the invocation must have access to the class itself. Therefore, methods of the class inside of which a private class is defined will have access to the public method, and methods of other classes would not have the access.
Of course if a private class inherits a public class or implements a public interface, the methods of the base class or the interface will be visible to everyone.