hi all... what is the 'private constructor' trap that Ajith refers to, in his potential traps list? are there some specific conditions under which a private constructor is not supposed to be used? thanks
Hi imran Whit a private construtor you can't make an instance of the Class in another class, I think that the best example about the private construtor is in Math Class, the construtor of Math is private, so you can't do: public class Test { Math myMath = new Math(); }
Marcelo Sousa Ancelmo - Brazil
imran anwar
Greenhorn
Joined: May 06, 2002
Posts: 12
posted
0
why is Math class's constructor private?
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
posted
0
becauase sun doesnt want you to make an instance of the class Math. so you cant do this: Math x=new Math(); // Wrong!! you dont need to do that because all the Math methods/fields are STATIC. thats means you can sue the class name to access them without creating an instance of that class.