Knute Snortum wrote:Public variables can be accessed by any class; private variables can only be accessed in the same class they're declared.
A.J. Côté wrote:Example:
Is using the package modifier
The rules about protected are slightly more complicated than that. It is defined as in the same package or in any code responsible for implementing the instance. So in subclasses, static methods don't constitute part of the instance, and (I think: you would have to check) protected members are not accessible.
A.J. Côté wrote: . . .
proctected: subclasses and classes in the same package
. . .
If “that variable” is a public variable of a public class anywhere in your classpath, yes.
Christopher Laurenzano wrote: . . . I can put that variable in another method, which is in another class and it will know what its value is? . . .
Which means it is not actually necessary to say anything about different packages.
Access to the member or constructor occurs from within the package containing the class in which the protected member or constructor is declared. Access is correct as described in §6.6.2.
Christopher Laurenzano wrote:Okay, Campbell Ritchie or anyone else -- I'm getting a better idea, and it's been a few days since I've been here.
Could you give me a description of what's happening in your code examples? I apologize but it's not quite clear yet. What's happening in those examples? I'm still a bit of a newbie.
Campbell Ritchie wrote:Agree with the last bit; if you make the name public you can easily run this sort of codeAnd there can be nothing worse than that.
Christopher Laurenzano wrote:What I meant in reference to the code example is what does the package and import statement do? can you tell me what's happening in the lines of code?
Christopher Laurenzano wrote:And what's happening in line 8 of the second example?
Christopher Laurenzano wrote:If I wanted to use the value of a variable from one class in another class, is it possible to do that?
Sorry for not replying earlier.
Christopher Laurenzano wrote:. . .
If I wanted to use the value of a variable from one class in another class, is it possible to do that?
. . .