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:
java.lang.Throwable at Battery.main(Battery.java:6)
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?
Joined: Oct 03, 2011
I ran the code
and got the following output
Exception in thread "main" java.lang.Throwable at battery.Battery.main(Battery.java:14)
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.