What statement should be entered to initialize c? Answer: this(a,b); My question is: why wouldnt this(a) work to init the second constructor() listed here?
Travis Benning
Ranch Hand
Joined: Jan 24, 2002
Posts: 74
posted
0
I'm not for sure, but i think it's because this refers to the super Test. if you want to just initialize the Test(int a) method, i think you need either this.Test(a). Am i right?
Sun Certified Programmer for Java 2 Platform
Darren Tweedale
Greenhorn
Joined: Jan 30, 2002
Posts: 16
posted
0
Ehrm, not sure. but I am puzzled about the answer. Who told you that? I haven't tried it yet, but at first glance I didn't think it would compile with the statement : c = b * (a / 12)? since the division would cause the result be to a float and "c" is an integer, so a cast would be required? Sorry, I am stumpted!
Originally posted by Darren Tweedale: but at first glance I didn't think it would compile with the statement : c = b * (a / 12)? since the division would cause the result be to a float and "c" is an integer, so a cast would be required?
Darren, since a is an int, (a / 12) would be an integer division. No conversion is done on the operands and a cast is not needed: the result would simply be truncated to an integer which is then multiplied by b. FWIW, I would agree that the original question is poorly structured.
I think answer is in-correct, we can have this(a) constructor call also . -SR
Originally posted by Paul Salerno:
What statement should be entered to initialize c? Answer: this(a,b); My question is: why wouldnt this(a) work to init the second constructor() listed here?