I have never asked myself this question but I think it make's sense. Scope is not so 
much related to instantiation than it is related to where a call is being made from 
within the object model.

The kind of behaviour you have in your code is similar to what you can do with inner 
and anonymous classes. Although they are separate classes they can access everything 
within their parent class. 

My understanding of scope has more to do with trust and security of the object model 
than trust and security during run-time. In other words, the private scope stops 
outside classes from trying to change how a class behaves: think of a software 
publisher who publishes an API for a certain functionality. So the Person object 
trusts an other Person object to access it's privates because they are the same. In 
other words p1, could never do to p2 something that p2 could not also do to itself! 
Sort of like how I trust a human doctor, but not an alien doctor to look at my 
privates! :-)

Although all this is a little weird it's still logical I think.

Florian Hehlen

>-----Original Message-----
>From: Thomas Sundberg [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, August 28, 2002 8:40 PM
>To: [EMAIL PROTECTED];
>[EMAIL PROTECTED]
>Subject: [Eap-features] Off topic question
>
>
>Hi!
>
>Could someone explain to me why this works? I has alway belived that 
>private variables were just private to that particular instance, but I 
>think this example shows that it is possible to reach the value of a 
>private variable in another instance of the same class.
>
>Obviously I'm able to reach p2.name in the exmpale below from 
>p1.display(). 
>(I know beacues the class compiles and runs...)
>But I can't explain why at the moment.
>
>Anyone?
>
>public class Person {
>     private String name = null;
>
>     public Person(String namn) {
>         this.name = namn;
>     }
>
>     public void display(Person p) {
>         System.out.println(p.name);
>     }
>
>     public static void main(String[] args) {
>         Person p1 = new Person("Putte");
>         Person p2 = new Person("Quarolin");
>         p1.display(p2);
>     }
>}
>
>/Thomas
>
>_______________________________________________
>Eap-features mailing list
>[EMAIL PROTECTED]
>http://lists.jetbrains.com/mailman/listinfo/eap-features
>

Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.

_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://lists.jetbrains.com/mailman/listinfo/eap-features

Reply via email to