The correct answer is the first one: Hello.
When this code is run, and when the so-called main method is reached, it will print out Hello.
Then it will return 10 as a a long.
It is legal for a method to both print to console and then return a value, so long as the print happens first.
This particular method is horribly named, and should never exist in real code. It is in the legal-but-horribly-wrong category, like naming methods identically to constructors.
As others have noted, the main method is really not.
Thus, Hello is a valid answer to the question as written.
Here you need to decide what it is you really want to ask about, then write a proper question. Several different topics could be tested here: method signatures, return values, unreachable code.
enthuware.ocajp.i.v7.2.1230 given answer is incorrect
Moderator: admin
-
- Posts: 6
- Joined: Mon Jun 29, 2015 8:41 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: enthuware.ocajp.i.v7.2.1230 given answer is incorrect
Did you try compiling and running the code?
The question and the given answer are correct. It is also quite reflective of the questions you may get on the real exam. The exam does contain questions that throw you off by presenting code that should never be written in real world. You are required to spot the errors in such code.
HTH,
Paul.
The question and the given answer are correct. It is also quite reflective of the questions you may get on the real exam. The exam does contain questions that throw you off by presenting code that should never be written in real world. You are required to spot the errors in such code.
HTH,
Paul.
Who is online
Users browsing this forum: Google [Bot], Shiftingsandsxlc and 9 guests