aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which constructor question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "which constructor question" Watch "which constructor question" New topic
Author

which constructor question

Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172

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
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
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!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4118
    
    2

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.


Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
sun ram
Ranch Hand

Joined: Dec 18, 2001
Posts: 61
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?


SCSecA,SCNA,SCSA,SCWCD,SCJP
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: which constructor question
 
Similar Threads
this
SCJP 5 Guide by K&B: Q5. Page 391 / 402
Flow Control -JQ+
confusing for Loop.
shift Operators