Handout3-TypesofQuestions-OCA Java SE 8 Programmer I PDF
Handout3-TypesofQuestions-OCA Java SE 8 Programmer I PDF
■ No file or directory path names for classes—If a question doesn’t state the filenames
or directory locations of classes, then assume one of the following, whichever
will enable the code to compile and run:
– All classes are in one file.
– Each class is contained in a separate file, and all files are in one directory.
■ Unintended line breaks—Sample code might have unintended line breaks. If you
see a line of code that looks like it has wrapped, and this creates a situation where
the wrapping is significant (for example, a quoted String literal has wrapped),
assume that the wrapping is an extension of the same line, and the line doesn’t
contain a hard carriage return that would cause a compilation failure.
■ Code fragments—A code fragment is a small section of source code that’s pre-
sented without its context. Assume that all necessary supporting code is present
and that the supporting environment fully supports the correct compilation
and execution of the code shown and its omitted environment.
■ Descriptive comments—Take descriptive comments, such as “setter and getters go
here,” at face value. Assume that correct code exists, compiles, and runs success-
fully to create the described effect.
WHAT ARE THE TYPES OR FORMATS OF QUESTIONS THAT I CAN EXPECT IN THE EXAM?
The exam uses different formats of multiple choice questions, illustrated in this sec-
tion by eight example questions with figures.
The examples for all these types of questions show how the following set of topics
might be tested using a different question format:
■ Correct declaration of the main method
■ Passing command-line parameters
■ Overloaded methods
■ Significance of method parameter names
■ Declaration of variables of varargs
Exam question type 1 (figure 4)—Includes simple code, but tricky or confusing answer
options.
Exam Tricky or
Simple
question = + confusing
code
type #1 answer options
Figure 4 Exam question type 1
The answer options in the following example would confuse a reader on whether the
command-line values would be concatenated or added as integer values:
FAQs 13
Given:
class JavaCertQType1 {
public static void main(String... cmd) {
main("private", cmd);
}
private static void main(String type, String[] args) {
System.out.println(args[0] + args[1]);
}
}
1
1 11
111
12
1 11 EJava Guru
Compilation error
Runtime exception
NOTE In this book, the sample exam questions at the end of each chapter
and full mock exam at the end of the book show answer options as lettered
(for example, a–d) for ease on discussion. In the exam, however, the answer
options aren’t numbered or lettered. They’re preceded with either a radio
button or a check box. Radio buttons are for questions with only one correct
answer, and check boxes are for questions with multiple correct answers.
Exam question type 2 (figure 5)—Exam questions without code give you a much
needed break from reading code. But it isn’t always easy to answer them.
Question2) Assuming that the phrase 'the method main' refers to the method
main that starts an application, select the correct statements (choose 2
options).
A class can define multiple methods with the name main, but with
different signatures.
The method main can define its only method parameter of type varargs.
Accessibility of the method main can't be restricted to private.
A class with overloaded main methods won't compile.
14 Introduction
Exam question type 3 (figure 6)—Reading though and comprehending lots of code can
be difficult. The key is to eliminate wrong answers to find the correct answers quickly.
An example:
Given:
class JavaCertQuesType3 {
public static void main(String args[]) {
System.out.println("Spring");
}
public static void main(String... args) {
System.out.println("Summer");
}
public static void main(String[] cmd) {
System.out.println("Autumn");
}
public static void main() {
System.out.println("Winter");
}
}
Exam question type 4 (figure 7)—This type of question is a classic example of “fill in
the blank.”
An example:
Given:
class JavaCertQType4 {
static int c, a = 10, b = 21/2;
static {
c = a;
}
// INSERT CODE HERE
}
Exam question type 5 (figure 8)—This question type will include code, a condition,
or both. The answer options will include changes and their results, when applied to
the code in the question. Unless otherwise stated, changes in the answer options
that you choose are applied individually to the code or the specified situation.
Result of a correct answer option won’t involve changes suggested in other correct
answer options.
An example:
Given:
1. class JavaCertQType5 {
2. protected static void main() {
3. System.out.println("EJavaGuru.com");
4. }
5. public static void main(String... method) {
6. main();
7. System.out.println("MissionOCAJ8");
8. }
9. }
Exam question type 6 (figure 9)—Because your mind is programmed to select the cor-
rect options, answer this type of question very carefully. My personal tip: cross fingers
in one of your hands to remind you that you need to select the incorrect statements.
Exam Select
question = Code + incorrect
type #6 options
Figure 9 Exam question type 6
An example:
Given:
1. class JavaCertQType6 {
2. public static void main(String... method) {
3. main();
4. main(method);
5. }
6. protected static void main() {
7. System.out.println("EJavaGuru");
8. }
9. }
Exam question type 7 (figure 10)—This question won’t include any code in the text of
the question; it will state a condition that needs to be implemented using code given
in the answer options.
Exam
No Answer options
question = +
code with code
type #7 Figure 10 Exam question type 7
An example:
Which of the following options can be used to define a main method that
outputs the value of the second and fourth command parameters (choose 2):
Exam Diagram
Answer options
question = representing +
as code
type #8 the code Figure 11 Exam question type 8
18 Introduction
An example:
5 7 5
7 7 5 5
5 7 7 5