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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1506
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: accessing private member/method from a diff class.
 
Similar Threads
Protected modifier
Why This access violation?
can't access finalize() method !!!
Private Modifer
can we override private method?