class C{
private int p;
static void fun1() {
C a = new C();
a.p = 2; // p is definitely accessible here -- // private means it can be accessed within the same class.
} // so we'll create a setter method so that we can let other classes set the value of p public setP( int newValue ) {
p = newValue;
}
}
public class D{
public static void main (
String[] args) {
C c= new C();
c.p = 4; // not allowed class D doesn't have access to p, its private!
c.setP( 8 ); // the method setP() is public -- so you use that to set the value of P
}
}
u call p from its class object
C c= new C();
c.p = 4; //
"C" is object of c class
and calling c.p;
is private is not accessible throw his class object
if it is out of class
thanx
Faheem