Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object creation Problem

 
Deepak here
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();

}
}
 
Guido Sautter
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic