Here in below program Block1 initializes z values as 20 and Block2 initializes z values as 30.
public class Scopevariable {
public static void main(String[] args) {
int x,y;
x=10;
y=20;
if(x==10){
int z=20;
System.out.println("The Value of z inside Block 1 is " +z );
}
if(x==10){
int z=30;
System.out.println("The value of z inside Block 2 is " +z );
}
}
}
public class Scopevariable {
public static void main(String[] args) {
int x,y;
x=10;
y=20;
if(x==10){
int z=20;
System.out.println("The Value of z inside Block 1 is " +z );
}
if(x==10){
int z=30;
System.out.println("The value of z inside Block 2 is " +z );
}
}
}
No comments:
Post a Comment