I've just finished the final test from ExamLab (priceless software!) and bumped into this one. It's purpose is to put the elements into the code so that it is compile-free and runs without exceptions. My answer was marked as wrong because of the type result of DateFormat.parse(...). I've insert Object and in the solution there was a Date (check the attached image).
I've put this code into Eclipse, compiled, execute and either solution is in my opinion right - no compile time errors and no runtime exceptions.
My question is - in real exam (in drag and drops), is there EXACTLY only one right solution for the given task?
Thanks in advance for all replies. I'm going to take the OCPJP 6 exam on Friday (24.09.2010).
The object returned over here is a Date object and it got implicitly typecasted to Object when you collected it in a Object reference. and now you cannot use the date object returned unless you type-cast it again.
if instead of DateFormat.parse(..), it was keySet() and you collect it in an Object, it would still compile:
but then you would have to typecast it again to Set, to retrieve the Set object from it, without explicit cast object 'o' is not of any use.
So, There can be more than one answers for drag and drop questions, but in your question, it should be collected in Date object only
In my opinion it just lacks of some information or exemplary usage of the "x" object at the last line of "main" method, just like, i.e. x.getTime() which would prevent from such a problems.
I understand that the o type reference needs to be downcasted to the java.lang.Date object if you want to use it this way, BUT it wasn't the purpose of this task. There is no usage of the "x" in code. The purpose was just to make the code compile and run.
It's just the first time I see a D&D with multiple valid solutions, therefore I wanted to know if this situation can happen on the real exam.
I will follow the Martin Vanyavchich's "answers should be as specific as possible" advice, but I still think the code template it should be more precise... But then again, maybe I'm just too suspicious after having too much ExamLab questions? :-))
BTW: Nice to meet the author of such a great learning platform which is available free - chapeau bas my friend! :-)
If it might help, I've bumped into one other thing in mock test nr 3, question 60.
Despite some error with layout (don't know if it's fault of my particular installation or is it a global error), after finishing the exam I've copied the program to the notepad and tried to analyze it. I think the answer should be C rather than B, which is "false", as that's the result of the code execution and also that's what the explanation tells us:
This return boolean value (false) (....) will be printed by the statement System.out.print(ob);
I checked this with the current database, and this error was already resolved. I don't remember when I corrected that, though.
The layout problem is not only for you. The next upgrade will be soon available with a fix for that.