Page 1 of 1

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

Posted: Sat Jul 26, 2014 7:43 pm
by Brian B
Wouldn't this technically return nothing? It compiles fine, but when run, the output from the compiler is nothing. Is the question referring to what the return value of trim() method is or the output of the compiler?

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

Posted: Sat Jul 26, 2014 8:30 pm
by admin
The statement is a method call. So its return value (which is what is asked by the question) will be the value returned by the method.

If you want to print that return value, you can put it in System.out.println(" hello java guru ".trim());

Whether you print it or not, the value is still returned by the call.
HTH,
Paul.

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

Posted: Fri Nov 13, 2015 4:50 am
by toolforger
It's the expression that returns a value.
The statement is an expression statement that simply discards the returned value.

While that's not the only view one can take, I do not think it is less correct, so the wording is at least ambiguous.
That's actually fine if the official OCA exam has the same kind of ambiguities; after all, we're taking the mock tests to prepare ourselves for the exam, less for testing our Java abilities (sad as that may be).

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

Posted: Fri Nov 13, 2015 9:02 pm
by admin
From the exam pov, you will see the terms, line of code, statement, and expression used interchangeably. We haven't seen questions in the exam that require you to differentiate based on the precise meaning of these terms.

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

Posted: Sat Nov 14, 2015 2:06 pm
by toolforger
Ah ok, thanks for the clarification.