About Question enthuware.ocajp.i.v7.2.1098 :

Moderator: admin

Post Reply
prateeks
Posts: 3
Joined: Sun Jun 23, 2013 10:48 am
Contact:

About Question enthuware.ocajp.i.v7.2.1098 :

Post by prateeks » Mon Jun 24, 2013 7:26 am

The last option states-
If (1) was a valid constructor 'int' would be promoted to long at the time of passing.
How can an int be promoted to long. int will be boxed to Integer, How can that Integer be converted to long then?

admin
Site Admin
Posts: 8545
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1098 :

Post by admin » Mon Jun 24, 2013 7:48 am

In this case int will not be boxed into an Integer. It will be promoted to long because that is the type of the argument in //1. This is a rule of the language: http://docs.oracle.com/javase/specs/jls ... #jls-5.1.2

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

chronix
Posts: 5
Joined: Mon Jan 04, 2016 12:28 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1098 :

Post by chronix » Mon Jan 04, 2016 11:26 pm

Why trick testers with these kind of questions. Wouldn't it defeat the purpose of
measuring what the testers know? After answering many questions I almost selected
the wrong option here. Exhaustion and stress plays a lot when taking tests.

admin
Site Admin
Posts: 8545
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1098 :

Post by admin » Tue Jan 05, 2016 12:37 am

You are right but unfortunately, the real exam does test a candidate on finer points of the Java language.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

brianwcraig
Posts: 1
Joined: Tue Mar 06, 2018 10:14 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1098 :

Post by brianwcraig » Thu Mar 08, 2018 8:48 am

I am looking at question v8.2.1098 and line 1 is stated as
public void TestClass(long pLong) { l1 = pLong ; } //(1)
"The declaration at (1) declares a method, not a constructor because it has a return value. The method happens to have the same name as the class, but that is ok."

void is now returned, so this is now a valid constructor, was the question text updated and not the answer or am I missing something ?

UPDATE (answered my own question):
"void" is the return value.
For it to be a valid constructor it would be stated: public TestClass(long pLong) { l1 = pLong ; } //(1)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests