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

Object Initialization Question

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
public class Test19 {
float f;

Test19(){
this(f);
f = 3;
}

Test19(float f){
System.out.println(f);
}
just explain me the flow here
for the above code u had replies as
Mamber variables gets initialized only after the call to the constructor completes.
To be more specific the constructor is intended to construct or initilize the members
i didnt get it.

public static void main(String args[]) {
Test19 t = new Test19();
}
}
[ October 17, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In your code the member variable 'f' is passed before getting initilized to the other constructor and hence you are getting the error.

But the static variables gets initilized when the class loads. So I guess this code will execute when f is declared as static.
[ October 17, 2005: Message edited by: Srinivasa Raghavan ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
It seems that this thread is a follow-up to another threadhere

Please reply in the same thread, not start a new one directed at individuals.
Thanks
-Barry
 
    Bookmark Topic Watch Topic
  • New Topic