File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes some odd answers from the K&B CD - part 4 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 "some odd answers from the K&B CD - part 4 " Watch "some odd answers from the K&B CD - part 4 " New topic

some odd answers from the K&B CD - part 4

John Schubert
Ranch Hand

Joined: Sep 21, 2011
Posts: 39

Here's the part four! Today (or tonight, depending on where do you live) a couple of questions:

Open book #2 exam, question 22

The question is:
What is the result?

The answer was:
D fin Then a runtime exception

But actually if you execute the code, no exception (and no RuntimeException at all) is thrown. If you print the stack trace, it looks like this:

at Battery.main(

And inspecting the thrown object, it is a plain Throwable whose cause is itself. (BTW, I'm of the opinion that the Throwable class should be abstract).

Open book #2 exam, question 44
Given a class House, which are true (Choose all that apply)
A House has-a Roof would be considered tight coupling
D House has-a Door would be considered low coupling

A is incorrect and D is correct. What I don't understand is how, withouth examining the source code of at least one of the classes, can we say if a composition scheme is coupled or not.
The reference says nothing about why D is correct. About why A is incorrect, it says:
A is incorrect because a House almost certainly will have a Roof, so this is not considered tight coupling.

But I don't understand why. Perhaps it means that in absence of source code, every composition should be considered loose coupling?
Puneet Chadha

Joined: Oct 03, 2011
Posts: 4
I ran the code
and got the following output

Exception in thread "main" java.lang.Throwable
at battery.Battery.main(
Java Result: 1

which is expected as the code is throwing an object of Throwable Class and trying to catch it with an Exception object in the argument of catch block.The Throwable object is not caught as shown in the output.finally will always be run unless System.out.exit() is called.
John Schubert
Ranch Hand

Joined: Sep 21, 2011
Posts: 39

Similar result than mine. But the answer marked as correct is misleading because it uses the words "runtime exception" and no exception is thrown, since a Throwable IS-NOT-AN exception.
I agree. Here's the link:
subject: some odd answers from the K&B CD - part 4
It's not a secret anymore!