• Post Reply Bookmark Topic Watch Topic
  • New Topic

OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 4 Question 16 Errata?  RSS feed

 
Ranch Hand
Posts: 185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is both m3 and m4?  Or should I have interpreted the question to be which line of code is the first to cause the ArrayIndexOutOfBoundsException?
Chapter4Q16ErrataQuestion2017-05-27_12-28-49.png
[Thumbnail for Chapter4Q16ErrataQuestion2017-05-27_12-28-49.png]
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles,
Once line m3 throws the exception, the code is no longer continuing to run. Since m4 never runs, it doesn't  have the opportunity to throw an exception. I agree that if line m3 were commented out, line m4 would be the answer.

Also note that only one answer is correct in all chapters except the two mock exam chapters. And in the mock exam chapters, we tell you how many are correct if more than one.

We do this to better simulate the exam where you know how many are correct. Which lets you use the # of answers as a clue to the answer - a good skill to have for the real exam!
 
Charles O'Leary
Ranch Hand
Posts: 185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed ... trying to find ways to increase my speed (18 & 26 use "first"  ... book thorough has been pretty consistent about treating each line separately)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles,
We tried to write "first" with compiler errors. The reason being you get all the compiler errors at the same time when you type javac. There's still a "first" one, but it feels less straightforward. For #16 (runtime), it is more clear what causes the error.

Note i said "tried". I'm sure there are examples in the book where we didn't follow this.
 
Charles O'Leary
Ranch Hand
Posts: 185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood.  Thanks Jeanne.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!