I am reading about the Oracle Java SE 7 Certified Programmer Level 2. I looked at the sample questions on their website and found this one which answer I cannot understand.
import java.util.*;
public class MyScan {
public static void main(String[] args) {
String in = "1 a 10 . 100 1000";
Scanner s = new Scanner(in);
int accum = 0;
for(int x = 0; x < 4; x++) {
accum += s.nextInt();
}
System.out.println(accum);
}
}
What is the result?
A) 1
B) 11
C) 111
D) 1111
E) Compilation fails.
F) Class2 has-a
Class1.
G) An exception is thrown at run time
The right answer is F. What does that answer mean?
You would receive an Exception at Run Time.
It is because, it fails during second iteration when it tries to match
a