aspose file tools*
The moose likes Beginning Java and the fly likes accessing private member/method from a diff class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "accessing private member/method from a diff class." Watch "accessing private member/method from a diff class." New topic
Author

accessing private member/method from a diff class.

Rajendra Deshpande
Ranch Hand

Joined: Nov 24, 2000
Posts: 40
Consider the class defn below..
class Beta {
void accessMethod() {
Alpha a = new Alpha();
a.iamprivate = 10; // illegal
a.privateMethod(); // illegal
}
}
'iamprivate' and 'privateMethod' are both declared as private in Alpha. I fail to understand how the 2 stmt in accessMethod are illegal despite the fact that they belong to object 'a'.
TIA.

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, the are private and belong to object a. But a is defined in a different class. That's why they are not accesible.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing private member/method from a diff class.