• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic