• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Object creation Problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can smbdy pls tell me y this code doesn't work..??
public class SuperTest {
float f;
SuperTest()
{
this(f);
f = 0.1f;

}
SuperTest(float f)
{
System.out.println("called test"+f);
}
public static void main(String[] args) {
SuperTest st =new SuperTest();

}
}
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepak,

it seems you pass the local field f to the second constructor, where you print it to System.out. Only after that, you assign 0.1 to it. So i guess the output is always "called test0.0".
What output did you expect, or what does not work. If you are more specific in your questions, it's way easier to give specific and useful answers.

Cheers, Guido
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!