SCJP Question Type 1: The “Results” Pattern

Introduction

The following problem adheres to the “Results” pattern:

prob11

The majority of problems on the SCJP exam follow the “Results” pattern. These problems can vary greatly in difficulty, mainly dependant on how complicated the code fragment is. They can cover a variety of topics and frequently try to trick you into assuming that they are testing one thing when they are actually testing another. It pays to be careful and methodical when approaching a “Results” pattern problem.

Answer Choices

The number of answers you must select varies in the “Results” pattern. Typically there will be only one correct answer, but sometimes the question will direct you to choose two or three answers. The question will usually include at least “Compilation Fails” as an answer choice, and frequently “Exception thrown at runtime” is also an option. The rest of the answers choices usually represent possible output produced by the program.

Occasionally you will come across a set of answer choices that points you toward a specific compilation error or exception thrown. For instance, “Compilation fails due to error on line 3” may be one possible choice. These answers are usually easy to rule out since they force you to look at only one line of code instead of the entire fragment.

Solving The “Results” Pattern

Every problem type on the SCJP can be solved in at least two obvious ways. The straightforward (Front Door) method will be presented first – this is the way that the exam designers intend for you to solve the problem.

The Back Door method can be helpful in a number of ways. If you can’t determine an answer to the problem using the Front Door method, the Back Door method gives you another way to look at it that might make the answer more apparent. The Back Door method can also be used to save time, to eliminate impossible answer choices to improve your chances of a correct guess, or even to check your work once you complete the Front Door method.

The Front Door:

  1. If the “Compilation Fails” answer choice is present, the first thing you need to do is verify that the code compiles. As always, check for problems with modifiers (such as a static method that calls an instance method without an object reference), unreachable code, and mismatched method arguments.
  2. Once you’re sure the code compiles, your second step is simply to execute the code as your JVM would do. You will be provided scratch paper during the exam, so make sure you use it if the code is at all confusing. This also forces you to take it slow, one line at a time, the way your JVM would do it. If the answer is constructed in multiple parts (like in the example), make sure you write down each part of the answer as it is calculated. Otherwise, you’re likely to misremember something at some point during the exam and get the problem wrong because of it.
  3. Once you have completed your run through the code, compare your answer to the answer choices. If your answer matches one of the answer choices, mark it and move on.

The Back Door:

  1. Look at the first answer choice and try to prove that it cannot be correct. For instance, in the example provided, an IOException is thrown from within the try block. It should be clear, then, that the exception will always be caught in the first block, and the second block will never execute. Thus, any answer with a “2” in it cannot possibly be correct.
  2. Repeat step 1 for each answer choice. In the end, there will only be one answer choice (or several if there is more than one correct answer) that you cannot prove is incorrect. Ideally, if you were able to solve the problem using the Front Door method, this solution matches the one you came up with earlier.

That’s the basic gist of the “Results” pattern. I’ll follow this up with a few more examples so that you can try out both of the strategies I described above. In the meantime, check out the previous post for some general tips and tricks if you haven’t done so already.

Got something to say about this post?  Let me have it!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s