Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.534 :

Posted: Sun Jan 25, 2015 10:23 am
by balttoma
This question contains the following piece of code:
float f = 1.23f;
...
f = null;
...

Not to be offensive, but if I copy paste those two lines into any java IDE, you will get a compiler error - the 'float' variable can not be assigned a null value. An error in the question?

Re: About Question com.enthuware.ets.scjp.v6.2.534 :

Posted: Sun Jan 25, 2015 9:22 pm
by admin
That is why the answer is 0 and what you say is exactly what the explanation says as well. "Further, you cannot assign null to primitives so this code will not compile."

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.534 :

Posted: Fri May 22, 2015 5:04 am
by pushpull
I think the question is wrong. Or there is no good answer here.
How many objects will be eligible for garbage collection at the end of this method?

Code: Select all

public float method(float pf)
{
 float f = 1.23f;
 float o = f = pf;
 f = null;
 o = null;
 return 0;
}
There will be no end of this method, cause it just won't compile. It's true that there are no objects in this code, but still asking about end of the method is strange.