Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static fields in inner classes

If I have class structure like that

public class Foo{
    //declaring fields and methods


    Foo(int k){
        Bar.a = k;
    }
    public class Bar{
        public final static int a;
    }
}

And if i create many instances of Foo, how does static field in class Bar acts? I mean, it is the same instance for all Foo objects or for each instance there is different static field?

like image 466
user2176737 Avatar asked Mar 16 '13 10:03

user2176737


1 Answers

I think that Inner class cannot have static members as it requires an instance of Outer Class.

like image 191
Rahul Tripathi Avatar answered Sep 29 '22 05:09

Rahul Tripathi