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 ]
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Why do you think the result is what it is? Would you have expected something to be different?
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
Joined: Mar 11, 2003
Posts: 21
posted
0
thanks, Karl. yuan
Yuan Tseng
Greenhorn
Joined: Mar 11, 2003
Posts: 21
posted
0
hi, is java has any kind of tools that can show me step-by-step (like vb)? thanks yuan
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
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.