wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Will this constructor work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Will this constructor work ? " Watch "Will this constructor work ? " New topic
Author

Will this constructor work ?

Men Gumani
Ranch Hand

Joined: Apr 01, 2009
Posts: 31


Thanks.
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Is there anything that makes you think it might not work?


All code in my posts, unless a source is explicitly mentioned, is my own.
Men Gumani
Ranch Hand

Joined: Apr 01, 2009
Posts: 31
The reason I raise this question is that I am reading chap 7 and I see a constructor like this :

I don't know if the one I asked will work or not, if you can explain at which stage the compiler knows type X is there and we can declare it, it would be great, even better if you can tell me the usage of such constructor.
Thanks again.
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
The usage of such a constructor is to be used in mock exams to confuse people. That's basically it. In the real world you shouldn't use obscure features of the language, but make your code easy to read and maintain.

The constructor you showed is equivalent to this one:

Men Gumani
Ranch Hand

Joined: Apr 01, 2009
Posts: 31
Oh? Sorry buddy, but you sure it is

not

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Men Gumani wrote:Oh? Sorry buddy, but you sure it is

not


Men,

I think it's the way I explained. This test seems to support that:

Men Gumani
Ranch Hand

Joined: Apr 01, 2009
Posts: 31
Thank you Ruben
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
No problem.
 
Consider Paul's rocket mass heater.
 
subject: Will this constructor work ?