2 Comments


  1. 15)

    It can not access the local variables of the method it is in though unless they are marked final. This is because the local variables of the method live on the Stack.

    class MyOuter {
    private int xxxx = 1020;

    void doStuff() {
    int yyyy = 222;//not private
    class MyInner {
    int zzzz =3333;
    void methodInner(){
    System.out.println(“dfhsdjfhkjds : ” + xxxx);
    System.out.println(“dfhsdjfhkjds : ” + yyyy);
    System.out.println(“dfhsdjfhkjds : ” + zzzz);
    }
    }
    MyInner inner = new MyInner();
    }
    // MyInner inner = new MyInner(); cannot access inner class of a method outside
    }

    here yyyy is not final but we can access inside method local inner class

    Reply

Leave a Reply.. code can be added in <code> </code> tags