posted 13 years ago
hi all,
in singeltoon classes we declare a method
public <classname_as Return aType> getInstance ()
{
// checking for null etc
// finally we return the instance object
return instance;
}
The instance object has an instance of its class (eg say Math class). This instance is called from a method(say X)/class(say A).
The method(X)/class(A) can used access the private members of the Math class as the object reference is copied. Doesn't this defeat the data secuity of the Math class?? I mean then there is no use in keeping the variables of Math class private as any class can get the instance of Math class by calling the public method Math.getInstance()
Is this true or am i missing something?
SCJP 6 83%
Working on SCWCD/OCPJWCD