ok the problem is i have done this piece of code and every thing seems ok till this part, i do not understand the error message, it says call to this must be first statement in constructor. what does it means the following is what i have done
well theres a few problems with this, and this is the main problem calls to this/super can only be made in constructors, and it has to be the first line of code, you tried to do it based on what your if returned to you. to get around this you could do the following
problem with that is contructors dont return any thing, so you'll get something like this printed out "Test@1". now to get around that you can print your output in the constructor.
now that will return the result you're looking for, alternatively you could use constructors for what they're intended for, to construct/initialiase your objects, and put your calculations into methods
Consider this: This constructor will do the following: 1. call super() 2. Make a new Test object with the Test(double, double) constructor. 3. Throw the newly created object away All resulting in not what you want. Consider using a factory method:
You will also need to add a String toString() to your class. This method should return a String representation of the object. [ March 19, 2003: Message edited by: Barry Gaunt ]
And the other bit of information to walk away with is: The very first thing every constructor does is to invoke a superclass constructor or another constructor in the same class. This invocation must be the very first thing to occur. So, you don't get to perform any logic to provide for alternate constructor chaining paths. Note that if you don't specify a superclass constructor invocation or the invocation of another constructor in the same class, the compiler slips one in for you - it provides a call to the no-argument superclass constructor. (Nevermind what Object's constructors do.)