• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in new exam question

 
Bhuvana Dhruva
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
check out this ?

1. Given:
1.public class ArrayTest {
2. public static void main (String[] args) {i
3. Object[] ov;
4. String[] sa = { "Green", "Blue", "Red" };
5. ov = sa;
6. System.out.println("Color = " + ov[1];
7. }
8.}
What is the result?
A.fails to compile
B.prints Color=Blue
C.prints Color=Green
D.generates an exception at runtime

this code does not compile because of an extra i in line2. so the ans should be A and not B as given in the website. am i not right?
 
Sanjeev Verma
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Bhuvana
technically speaking, you are right. It is a typo on the part of the writer. But if you remove the typo, the answer is B. Just hope there are no Qs like this on the real exam. Gives me the jittersssssssss.
Regards
sanjeev
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic