aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question From Jaworski's Mock Test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question From Jaworski Watch "Question From Jaworski New topic
Author

Question From Jaworski's Mock Test

Barbara Dyer-Bennet
Greenhorn

Joined: Sep 14, 2000
Posts: 10
Here's one that is driving me crazy... how would I have gone about finding the answer in a reasonable amount of time?
1. class Question {
2. public static void main(String[] args) {
3. for(int i = 0; i < 10; ++i) {
4. try {
5. if(i % 3 == 0) throw new Exception("E0");
6. try {
7. if(i % 3 == 1) throw new Exception("E1");
8. System.out.println(i);
9. }catch(Exception inner) {
10. i *= 2;
11. }finally {
12. ++i;
13. }
14. }catch(Exception outer) {
15. i +=3;
16. }finally {
17. ++i;
18. }
19. }
20. }
Which lines of output are displayed by the program above (select all that apply)?
A. 4
B. 5
C. 6
D. 7
E. 8
F. 9
Thank you,
Barbara
(The mock test gives the answer as B & E.)

[This message has been edited by Barbara Dyer-Bennet (edited September 14, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, Barbara,
The program is executed in following steps:
1) line3: ForInit part : i = 0; and ForExpression i < 10 is true
2) line5: i%3==0 is true, then throw an Exception
3) lint14: the Exception caught, then i += 3; so i = 3
4) line16: ++i, so i = 4;
5) line19: ForUpdate part: i++, so i = 5;
6) line3: and ForExpression i < 10 is true
7) line8: output : 5
8) lint11: finally ++i; so i = 6
9) line16: finally ++i, so i = 7;
10) line19: ForUpdate part: i++, so i = 8;
11) line3: and ForExpression i < 10 is true
12) line8: output : 8
13) lint11: finally ++i; so i = 9
14) line16: finally ++i, so i = 10;
15) line19: ForUpdate part: i++, so i = 11;
16) line3: and ForExpression i < 10 is false, for statement is end, and program is terminated.
Hope helpful!
Yiqing
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
By the way, can u tell me how to get Jaworski's Mock Test?
Thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
my email: yiqingye@szonline.net
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
The Jaworski's mock tests are here.
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
Hi yiqingye!
Your explanation of the question was quite good however I lost track line 4 .On line5 you mentioned "ForUpdate".What is that?
Please explain that .
Thanx in advance,
Ira
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question From Jaworski's Mock Test