Hi ranchers, Pls. consider the following code snippet taken from a tech web site. I have two queries here: (1) Is it a must to define the no-args default constructor explicitly? What's the harm if we rely on the Java compiler provided default constructor?
(2) Why do we need a static variable here. We know that there's just one copy of any static variable irrespective of inatances created. But, I wonder if there would be more than one instance of ReqListener class in any scenario.
1) No there is no harm in relying on the default, no-arg constructor. Remember though, the default constructor is only created if no others exist. If you create any other constructors, then you must, if you need one, explicitly create the no-arg constructor as well.
2) The amount of code posted is not enough for us to say for sure that only one instance of that listener is going to be created. [ February 28, 2007: Message edited by: Ben Souther ]