File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Private Access Modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Private Access Modifier" Watch "Private Access Modifier" New topic

Private Access Modifier

Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi All,

The above code compiles without any problem. According to me it should
not compile since in the 2nd line of main method since a private variable is directly accessed using object reference. And also the declaration of i is also making forward referencing to the j variable, which should also give an compilation error. Can any one give me proper explanation.......

Thanks and Regards,
Kalai Selvan T.
[ November 03, 2004: Message edited by: Kalai Selvan ]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
All your code is in one class, so access modifiers do not make any difference. A class can always see all of its own members: fields and methods.

Many types of "forward reference" are perfectly OK in Java. See the Language Specification for more details, if you care about them.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: Private Access Modifier
It's not a secret anymore!