• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Object visibility

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiall,
I've red the following on a
study note by "Ashraf Fouad Ayoub".
In a true false question.
could you explain me the following sentence:
Objects themselves do not have visibility, only references to the object
In what context?
What do you think it refer to?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that when declaring
private Object obj = new Object();
as an instance member of some class, it is the reference variable obj that is private to the class in which it is declared, not the actual Object instance refered to by obj (which is on the heap).
The object instance could be returned by some method in the class but the reference variable itself cannot.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
something like this...
The object can be modified by any object reference that can get a hold of it.
 
Igor Zeta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Now is better.
So is the same of saying:


An object although private can be updated having copy of its reference?

 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No! An object cannot be private or protected or whatever access you may want to give it. Only the reference to an object, that is the variable you are using for referencing the object, may have an access modifier.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


An object although private can be updated having copy of its reference?


Once you have a reference to this object you want to update it right. In order to update it you must call or access its members. This is when the access modifiers come into play again since you won't be able to call or access members of that object that have restricted access (private, default and you are in another package, protected and you are in another package and not a subclass).
reply
    Bookmark Topic Watch Topic
  • New Topic