• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Constructor Chaining

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
To all,Ranchez could anny buddy clear my doubt the execution
of constructors.ds can b done using this() and super().
Ex

There is Line written in Book Khalid & Mugal.dt Body of contructor is executed in reverse order.preety confusing plz help out

(added the tags for formatting code to look like code sort of)
[ March 24, 2005: Message edited by: Barry Gaunt ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, under the Add Reply button are ten buttons. One of them is the CODE button which will put CODE tags in your post, where you can paste your code in there and it will remain formated, it will keep its indentation which makes things easier to read.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It prints in reverse order because it calls another constructor first before it does the printouts.

So if you call the no args constructor, it first calls the two arg constructor, which then calls the three args constructor, runs 3's printout, then returns to the 2 arg constructor to its printout of "2", then back to the no args constructor, and there it prints its "1"

Hence, 3 2 1.

Mark
 
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think your code compiles, the instance field "indicator" cannot be referred to when you call a constructor of the class:

this(watts,indicator,"X");

Your code would compile when "indicator" is static but that is probably not the intention.
[ March 24, 2005: Message edited by: Thomas De Vos ]
 
deshdeep divakar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark thanks for ur guidance,I will take care of posting
and replying problems from now.

 
Yeah, but is it art? What do you think tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic