Private class in another class?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Private class in another class??

In Java, How can we use a class having private access in any other class which have public access.

20th Jun 2019, 5:15 PM
Prakash Joshi
Prakash Joshi - avatar
3 Answers
+ 3
When an attribute or method is considered private, it means that that attribute or method is only recognized by the class itself and can't be used outside of it. You can write a new class within the Java file that contains these methods for that class to be able to use them. If the classes that need the methods happen to be in the same package as the class that contains attributes and methods that you need them to use, change the access-modifier to protected. This allows the classes in that package can use it. I apologize if this wasn't really able to help you as your question was stated vaguely and this is my answer to the best of my ability.
20th Jun 2019, 7:27 PM
Z4R0 C0DING
Z4R0 C0DING - avatar
20th Jun 2019, 11:38 PM
Denise Roßberg
Denise Roßberg - avatar
20th Jun 2019, 11:43 PM
Denise Roßberg
Denise Roßberg - avatar