aspose file tools
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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.

rocket mass heater kickstarter
subject: Jxam - Just checking!