Skip to content
Advertisement

Can a object be private and public?

Can a reference to an object be private in class while other object can have a public reference to the same class(post script: new to java+ a simple example please). I read somewhere that this prob is regarding aliasing? Sorry my title may not make sense!

Advertisement

Answer

Objects aren’t private or public. Fields can be private or public. Fields can hold references to objects. An object can be referred to by both private and public fields simultaneously:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement