File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes Jxam - Just checking! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Jxam - Just checking!" Watch "Jxam - Just checking!" New topic

Jxam - Just checking!

Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
The following question:
Consider the following piece of code and select the correct statements.
1. Object o = new String("abcd");
2. String s = o;
3. System.out.println(s);
4. System.out.println(o);
This obviously won't compile because of the downcast in line 2. However, this answer was supposedly incorrect: Change line 1 to String o = new String("abcd"). Did I just lose my mind here?

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Gregory,
By changing the first line to String o = new String("abcd"); the downcast compiler error is effectively removed. Therefore, the code will compile with no errors.

I agree. Here's the link:
subject: Jxam - Just checking!
It's not a secret anymore!