*
The moose likes Beginning Java and the fly likes How is code executed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How is code executed" Watch "How is code executed" New topic
Author

How is code executed

Don Singh
Greenhorn

Joined: Jun 18, 2011
Posts: 18




Answer
third second first snootchy 420
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

hello rancher,

please ask specific question.... where you stuck don't ask full answer.... you harm yourself by asking full answer... let your brain think

Hint : we can call constructor from another constructor...
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
Hi,
When the code gets executed,it goes to default constructor i.e. it goes to Line 5 there 'this' is called it means it goes to corresponding super class.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

madhuri kunchala wrote:Hi,
When the code gets executed,it goes to default constructor i.e. it goes to Line 5 there 'this' is called it means it goes to corresponding super class.


how can this means super class ?? and also he is not extending any class please dont mis guide

deca leni
Ranch Hand

Joined: Jun 18, 2011
Posts: 49

we call "this" to current executing object.yep we can call constructor from another constructor.
then it goes according to the constructor calling chain

Do or die...?? No, Do before you die... || (SCJP .6)
Harnoor Singh
Ranch Hand

Joined: Aug 24, 2010
Posts: 35
Bootchy b = new Bootchy();

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
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.
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
Your constructor is the same name you used as the head name of the file.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

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?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
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.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

-- nevermind --
 
Don't get me started about those stupid light bulbs.
 
subject: How is code executed