In the main function we are creating the new object by calling constructor with no argument. So control reaches at line number 5. In this method we are specifically calling different constructor(with argument) of the same object. So the control reaches at line number 10. Similar thing is happening in constructor with one argument.
madhuri kunchala wrote:Hi,
When the code gets executed,it goes to default constructor . . .
What default constructor? The Bootchy class doesn't have a default constructor. java.lang.Object might have, but there is no default constructor here. Line 5 is not a default constructor, but a no-arguments constructor with an implemented body. The two are very different.
Campbell Ritchie wrote:What default constructor? The Bootchy class doesn't have a default constructor. java.lang.Object might have, but there is no default constructor here. Line 5 is not a default constructor, but a no-arguments constructor with an implemented body. The two are very different.
Yes Campbell, as usual you are technically correct (according to section 8.8.9 of Java Specification). But both you and me, and quite a lot of other people also knows that the term “default constructor” may additionally refer to a constructor that may be called without arguments.
Outside of the academic world, it is easier to tell a programmer "you need to create a default constructor" instead of saying "you need to create a no-argument constructor".
So, from a beginners point of view, how would you explain the difference between:
that is a default constructor per definition and
that is not?
Joined: Oct 13, 2005
It is just as easy to use correct terminology. There are enough people out there using wrong terminology. The reason for jargon is that it can be made precise. Saying "default" when yo umean "no arguments" reduces the value of our specialised language.
And your example is not actually "a default constructor per definition", but has exactly the same effect.