gurpeet singh wrote:i think you are confused between widening reference and widening primitive conversions. these are two seperate things. if Dog class subclass Animal and we write Dog d = new Dog(); Animal a = d; here widening reference conversion is happening. when we do long l = 989; here widening primitive conversion is happening. int is promoted to long implicitly. so and int can be promoted to Object in your example. first it is boxed to Integer wrapper which is then assigned to Object reference variable and hence widening reference conversion. Rest is explained by Pritish
James Boswell wrote:
Look at your method signature above and then look at what you are attempting to pass to the go method:
Notice the type for variable l?
Anurag Jai wrote:Hi Kedar....
As you know "finally" block is always executed, so when any exception is thrown from catch block......the exception in the finally block would be thrown from the exception instead of any exception occurring inside the catch or try block.
Pritish Chakraborty wrote:Follow the flow control, Kedar!
You throw an exception in the try block, which is silently caught by the catch block.
The catch block then rethrows the exception. Now either it will move up the call stack (out of main()), or it will be caught again.
But in the last fragment of code, a finally block is placed. A finally block runs regardless of whether an exception is thrown. In this case the exception *is* rethrown from catch, and is 'caught' by finally, which forcefully executes. I always considered finally as an offshoot of the catch(...) clause in C++ but let's not go there, finally has some fundamental differences.
Now if we rethrow from finally, the exception is thrown out of main() and is caught by the JVM, which prints the stack trace after halting the program execution.
Now try this - don't throw a new exception from finally. Post the result.