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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: accessing private member/method from a diff class.
 
Similar Threads
Private Modifer
Protected modifier
can we override private method?
can't access finalize() method !!!
Why This access violation?