Leave a Reply 3

Your email address will not be published. Required fields are marked *


ana

ana

C. myStr: 7007, myNum: 9009

renko

renko

Indeed, C is correct. Scope of the variables is important here

package q046;

public class App {
String myStr = “7007”;

public void doStuff(String str) {
int myNum = 0;
try {
String myStr = str; //”9009 -> scope myStr inside try-block only
myNum = Integer.parseInt(myStr);//9009
} catch (NumberFormatException ne) {
System.err.println(“Error”);
}
System.out.println(“myStr: “+ myStr //”7007 -> not local variable
+”, myNum: “+ myNum); //9009
}

public static void main(String[] args) {
App obj = new App();
obj.doStuff(“9009”);

}

}