accessing private member/method from a diff class.
Rajendra Deshpande
Ranch Hand
Joined: Nov 24, 2000
Posts: 40
posted
0
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
posted
0
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