File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Public variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Public variable" Watch "Public variable" New topic

Public variable

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
If variable a of class ABC in package 1 is Public but class ABC is private.
Can other class from other package 2 or same package 1 access variable a of class ABC in package 1 ?
Thanks in advance,
N Mukherjee
Ranch Hand

Joined: Jun 08, 2000
Posts: 141
Hi,'s not accessible.If the class is becomes the
deciding factor no matter what the access specifier your variable
is having.
It all depends on the class(first) and then variable(Second).
As the cl;ass is private it is not accessible from any package or any class
outside this package where the top class is.
Hope this helps.

"Knowledge is Power"****************<A HREF="" TARGET=_blank rel="nofollow">THREAD/SCJP RESOURCES</A>
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
HI N Mukherjee
Thanks a bunch!
Now I understood.
Also I would like to know then what about Protected means If it variable is Protected of class ABC of package 1 then can other class of same package 1 and also classes of package 2 access protected variable?
Thanks again
I agree. Here's the link:
subject: Public variable
It's not a secret anymore!