Write a program to demonstrate scope of a variable with in a block.

0
/* Write a program to demonstrate scope of a variable with in a block. */

class Scope{
    public static void main(String args[]){
        int x;
        for(x=0;x<3;x++){
            int y=-1;
            System.out.println("y="+y);
            y=100;
            System.out.println("y="+y);
            }
        }
    }

/*
Output:

E:>javac Scope.java
E:>java Scope

y=-1
y=100
y=-1
y=100
y=-1
y=100

*/

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts