dcsimg
What is the meaning of 'Scope'
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Qatz_Smith
Posted On:   Thursday, December 22, 2005 11:55 PM

For the last 6 years I've understood that the scope is the ability of accessing an object's member (attribute or method). But after seeing a example Java code and finding out that it compiled successflly... I've started to wonder that I was aways wrong. Not completely wrong, but still wrong. public class A { private int i; public copyValue( A a) { this.i = a.i; // accessing a's private attribute w/o an error } } Or is it that, the 'Scope' controls the accessibility of a class, and not the instance of a class. If the class that is calling the member and the class that is the owner of the member are the same class, then the caller can access all private members.    More>>

For the last 6 years I've understood that the scope is the ability of accessing an object's member (attribute or method). But after seeing a example Java code and finding out that it compiled successflly... I've started to wonder that I was aways wrong. Not completely wrong, but still wrong.

			
public class A
{
private int i;
public copyValue( A a)
{
this.i = a.i; // accessing a's private attribute w/o an error
}
}


Or is it that, the 'Scope' controls the accessibility of a class, and not the instance of a class. If the class that is calling the member and the class that is the owner of the member are the same class, then the caller can access all private members.

Can any one help me on the issue. Is there any sources of documents, theories, etc. that will support the issue.    <<Less

Re: What is the meaning of 'Scope'

Posted By:   Anonymous  
Posted On:   Sunday, February 12, 2006 08:26 AM

Your second paragraph is right - the 'private' keyword controls accessibility from other classes, not from other instances of the same class. Java relies on your own coding discipline to avoid directly accessing attributes across instances.

Leigh.

Fw: What is the meaning of 'Scope'

Posted By:   Qatz_Smith  
Posted On:   Friday, December 23, 2005 12:16 AM

I've miss typed the method. It must be ...

public void copyValue( A a)
{
this.i = a.i; // accessing a's private attribute w/o an error
}
About | Sitemap | Contact