Needs explanation plz..
I have observed the following but can not get the actual explanation. If anybody can explain this thenit will be helpfull for my knowledge base.
The problem is like this:
I have two classes A and B like below:
publicclass A
{
privateint i;
publicvoid setI(int x)
{
i=x;
}
publicint getI()
{
return i;
}
}
and
publicclass B
{
publicstaticvoid main(String args[])
{
A a=new A();
a.setI(10);
System.out.println(a.getI());
}
}
I have compiled both classes and execute classB. It is pretty simple to guess the output.
Now I changed the class A so that the permission of the function getI() and setI() is private: as follows:
publicclass A
{
privateint i;
privatevoid setI(int x)
{
i=x;
}
privateint getI()
{
return i;
}
}
Now I just compile class A only.. (I have not compile Class B because it has not been changed.)
Now I guessed that when I will execute class B it will give error since the setI() and getI() methods of class A is private now. But when I execute class B it is able access the setI() and getI() method and gives the output as same as before.
How this is possible?

