Meaningless Drivel is fun!*
The moose likes Associate Certification (OCAJP 7) and the fly likes OCA, Java SE 7 Programmer Study Guide: confused about test questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "OCA, Java SE 7 Programmer Study Guide: confused about test questions" Watch "OCA, Java SE 7 Programmer Study Guide: confused about test questions" New topic
Author

OCA, Java SE 7 Programmer Study Guide: confused about test questions

Vaidas vaidaskz
Greenhorn

Joined: May 10, 2013
Posts: 1
Hi,
I have read this book by Richard M. Reese, Packt Publishing (http://www.packtpub.com/oracle-certified-associate-java-se-7-programmer-study-guide/book), and I have some doubt about correctness of some test questions, because I don't find them in errata.

7. Inheritance and Polymorphism

3. What method is used to determine the type of an object?
a. isType
b. typeOf
c. instanceof
d. instanceOf

Correct answer is d. I don’t find in JDK any method instanceOf. And other names also can be used as method names.

4. Which of the following are valid casts?
a. num1 = num2;
b. num1 = (int)num2;
c. num1 = (float)num2;
d. num1(int) = num2;

supposed right answer is b. But how we can deside about casts correctness if we don’t know data types of num1 and num2? For example if num1 were of type short, b would be incorrect or if num1 were float and num2 int, c would be correct.

8. Handling Exceptions in an Application

1. Which of the following implement checked exceptions?
a. Class A extends RuntimeException
b. Class A extends Throwable
c. Class A extends Exception
d. Class A extends IOException

Correct answers are c and d. Why Throwable is not considered as checked exception? I can throw it and must deal with it explicitly.

5. What exceptions may the following code generate at runtime?
String s;
int i = 5;
try{
i = i/0;
s += "next";
}
a. ArithmeticException (+)
b. DivisionByZeroException
c. FileNotFoundException
d. NullPointerException (+)

Correct answers are a and d. But s += "next” does not generate NullPointerException, even if s is null, how can it be thrown from that code?

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

3. What method is used to determine the type of an object?
Weird question and even more weird answer options. The Object class has a getClass-method which can be used to get the class (type) of the object. The Class class has an isInstance-method to check if an object can be assigned to this class. The JDK has an instanceof operator to check if an object is an instance of a given class (type). So none of the answers are correct!

4. Which of the following are valid casts?
If the questions just wants to know which options use valid cast syntax (independent on the variable types) the correct answers are (b) & (c). (a) is not a cast, just an assignment (althought it could be an implicit cast, but unable to know without the variable types), (d) is just incorrect syntax.

1. Which of the following implement checked exceptions?
All Exceptions are Throwable, but a Throwable is not always an exception (e.g. OutOfMemoryError is a Throwable, is an Error, but it's not an Exception). Because the question asks for checked exceptions, only (c) and (d) are correct.

5. What exceptions may the following code generate at runtime?
This little snippet does not compile, because all local variables should be initialized before use. Variable s is not initialized, so the program will not compile (compilation fails would be the correct answer). If we assign null to variable s, the correct answer would be (a). It's tempting to think the string concatenation will throw a NullPointerException, but it won't (printing variable s will result in nullnext on the standard output).

The mock exam (test) questions sections are (one of) the most important parts in a study guide for a certification exam. If they contain a bunch of mistakes, the book becomes quite useless because these mistakes make students doubt about what they have learned instead of preparing them for the exam.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OCA, Java SE 7 Programmer Study Guide: confused about test questions
 
Similar Threads
EXCEPTIONS. PLS HELP!!!!
Run Time Error
Art and Science of Java Chapter 4 Exercise 7
"cannot find symbol variable..."
possible loss of precision