Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sun's New Sample Q&A. Java 2 Question 1

 
Bob Kerfoot
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Given:
public class ArrayTest {
public static void main (String[] args) {i
Object[] ov;
String[] sa = { "Green", "Blue", "Red" };
ov = sa;
System.out.println("Color = " + ov[1];
}
}
What is the result?
A. fails to compile
B. prints Color=Blue
C. prints Color=Green
D. generates an exception at runtime
Sun indicates that the answer should be B. However, the correct answer is A because the stray i following the opening curly prevents this from compiling successfully.
Looks like it's probably a typo but I sent the same comment to who2contact@central.sun.com anyway.
Bob Kerfoot SCJP - 92%
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right. Without the i, it would be B, but with the i, which I agree is probably a typo, it wouldn't compile. When I first saw it, I thought you made the typo
 
greg clarke
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fear not Bill. Look for the missing parenthesis in the output statement:
System.out.println("Color = " + ov[1];
So, remove the "i" and it still won't compile. Two typos in one question!?
Bob - how did Sun indicate to you the intended answer?

 
Bob Kerfoot
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg,
Sun never got back to me but they still list "B. prints Color=Blue" as the correct answer at the web site.
The missing ")" is definitely also a problem.
Hopefully the real exam questions are cleaner than those in the new sample.
Bob Kerfoot - SCJP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic