Local variables in java

Comments

  • Very Helpful Blog on Local Variables.

    Scope of Local variables is restricted within the block in which they are defined.

    Example:

    class A
    {
    int a=10, b=15;
    public static void main(String s[])
    {

        add();
    
    }
    static void add()
    {
        int a=15,b=10;
        System.out.println(a+" "+b);
    }
    

    }

    OUTPUT:
    15 10

    Local variables override the instance variables (member variables of class).

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion