• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on private access

 
George Jin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A
{
private int i;
public void modifyOther(A a1)
{
a1.i = 20; //1
}
}
Why a1 can access the private member i? Is it because this method within Class A?

Thanks
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is. Have you tried The Java Tutorial ?
 
praveena kuppachi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
A method or a variable that is declared private i s not accesible outside the class.Thats is only the members belonging to the class can acces it.it can be used by the instance of the class that declares it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic