File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Inquisition mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on Inquisition mock exam" Watch "Doubt on Inquisition mock exam" New topic

Doubt on Inquisition mock exam

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
The following code is from the inquisition SCJP quizz by the muppeteer:

import java.util.Set;
import java.util.TreeSet;

public class Testing123 {

public static void main(String... args)
Set t = new TreeSet();
for(Object o:t)System.out.print(o);


Choose one option

1 - Thise doesn't compile
2 - ab666
3- ab

My response was that none of the 3 (unfortunately there no such option), but the resulte is 1 (doesn't compile), and this is the reason given

Every collection with 'Tree' in it, need objects that implement Comparable. Next to that they have to be mutually comparable and Integer (666 is autoboxed) and String are not.

I tried to paste the code on my IDE and compile it, it compiles fine, and when I execute it, it raises the following exception :
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

So I think the response given bu the inquisition (option 1) is not correct

SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
marc weber

Joined: Aug 31, 2004
Posts: 11343

You are correct. Using javac, it compiles (with warnings). The exception is thrown at runtime.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Raphael Rabadan
Ranch Hand

Joined: Jul 05, 2008
Posts: 141
We need to take care with those mocks. Sometimes they do some mistakes like this. Like said before, it does compile, but will throw a ClassCastException in runtime when trying to compare a String to a Integer.
[ July 11, 2008: Message edited by: Raphael Rabadan ]

SCJP Java 6 (98%) - Story, SCJA (88%) - Story
Matt Russell
Ranch Hand

Joined: Aug 15, 2006
Posts: 165
Yep, that's a bug -- I'm guessing you must be running an old version (< 0.14) of Inquisition, because that error was fixed in the release last month.

Inquisition: open-source mock exam simulator for SCJP and SCWCD
Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
Thanks Matt,

Ok, I downloaded the newest version, an we have a forth option thats says "throws an exception at runtime"
I agree. Here's the link:
subject: Doubt on Inquisition mock exam
It's not a secret anymore!