Diagnostic Quiz
Problems
01. Subtype relationship with interface
interfacePay attention to the reflexive property of the subtype relationship. This willl ensure you get all the correct options! Don't miss one!
That is, if and , then
02. Type casting and compile-time error
To see whether a code will generate compile-error or not, we only see the CTT of the variable and the type casting. The casted type must be the subtype of CTT of L.H.S and should be withn the type hierarchy (either subtype of supertype) of the CTT of R.H.S
Type casting will cast the variable to that specific type dyuring the compile-time.
03. Type casting and rum-time error
Run-time error judgement only needs us to see the RTT of the variable. We must ignore the type casting!
As we have seen above, type casting is only done during the compile-time. So, during the run-time, we can just ignore the type casting and see the subtype relationship between the RTT of the L.H.S and R.H.S variable.
04. Wrapper class
All primitive wrapper class objects are immutable.
This means that once a wrapper object is created, its value cannot be changed. If you want to modify the value, you have to create a new object.
14. Exception Hierarchy
The following image summarise the Exception Hierarchy well!

16. throw as return
throw as returnIn the try-catch-finally exception handling block, the throw statement has the same purpose as return, meaning that it will jump directly from the current block and may enter the next block.
For example, the following code will print BD at the end.
Tips
Pay attention to the reflexive property of the subtype relationship. This willl ensure you get all the correct options! Don't miss one!
To see whether a code will generate compile-error or not, we only see the CTT of the variable and the type casting.
Run-time error judgement only needs us to see the RTT of the variable. We must ignore the type casting because Java is strongly typed, meaning objects always retain their actual type (RTT).
Include the exception hierarchy in the cheatsheet!
Last updated