How can an int be promoted to long. int will be boxed to Integer, How can that Integer be converted to long then?If (1) was a valid constructor 'int' would be promoted to long at the time of passing.
About Question enthuware.ocajp.i.v7.2.1098 :
Moderator: admin
-
- Posts: 3
- Joined: Sun Jun 23, 2013 10:48 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1098 :
The last option states-
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1098 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Mon Jan 04, 2016 12:28 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1098 :
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.
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1098 :
You are right but unfortunately, the real exam does test a candidate on finer points of the Java language.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Tue Mar 06, 2018 10:14 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1098 :
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)
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)
Who is online
Users browsing this forum: No registered users and 92 guests