QuestionQ202

Handling Exceptions

Given:

Question Image

What is the resulting output?

  • A myStr: 9009, myNum: 9009
  • B myStr: 7007, myNum: 7007
  • C myStr: 7007, myNum: 9009
  • D Compilation fails
Explanation

The myStr declared inside the try block shadows the instance field only within that block. It is parsed into myNum as 9009. Outside the block, the local variable is out of scope, so myStr refers to the instance field, which remains "7007".

Community Discussion

No comments yet. Be the first to start the discussion!