• 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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i was studying the book 'thinking in java'. and
is anyone can explain to me why have this result?

the output:
Tag (1 )
Tag (2 )
Tag (3 )
Card()
Tag (33 )
f ()

thanks for your help,
yuan

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 13, 2003: Message edited by: Dirk Schreckmann ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think the result is what it is? Would you have expected something to be different?
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

if changed the order of variables in the class Tag. The constructor is only called after the varibales are initialized.


Here is what happens:
  • 1) New Card is created
  • 2) This first inits all variables of the class (t1, t2, t3) by calling the constructor of Tag (i guess you cant be shure that they are called in the order of appearance. im not sure about that)
  • 3)After all variables are initialized, the Constructor of Card is executed
  • 4) then t3 is reassigned to a new instance of Tag -> constructor of Tag is called again
  • 5) and then the function f() is called


  • hope this helps.

    k
     
    Yuan Tseng
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks, Karl.
    yuan
     
    Yuan Tseng
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi,
    is java has any kind of tools that can show me step-by-step (like vb)?
    thanks
    yuan
     
    Ranch Hand
    Posts: 7729
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you are new java then a nice little learning IDE can be found on the BlueJ site. It has a debugger and class inspector and will soon have JUnit capability.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic