• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How is code executed

 
Don Singh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Answer
third second first snootchy 420
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
Java Java ME PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we call "this" to current executing object.yep we can call constructor from another constructor.
then it goes according to the constructor calling chain
 
Harnoor Singh
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor is the same name you used as the head name of the file.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-- nevermind --
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic