This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi Vineela and Sanjay, Either way no-arg constructor is the default constructor. Regards Maulin
Joined: Mar 26, 2004
Maulin, That's not what I read, even though it's more of a linguistic/semantic kind of discussion whether it should be this way or not, here is an excerpt from K&B (Page 315, last paragraph) :- A no-arg constructor is not ncessarily the default constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.
A no-arg constructor defined by you is not necessarily the same as the "default" constructor you'd get if you didn't define a constructor. You can read about it in the JLS, §8.8.7 Default Constructor, but here are a few things to keep in mind. 1. The default constructor takes on the same access modifier as the class. Therefore, a public class would have a public default constructor. If you were to define a public class with a no-arg private constructor, you'd have a different no-arg constructor. 2. The default constructor has no throws clause. If you were to define a no-arg constructor that could throw an exception, it would be different from the default constructor. 3. And, of course, the default constructor is special in that it is provided for you, unlike any constructor that you would define. I hope that helps, Corey