- X 2
After that, if your class is a nested or inner class, and if that nested class does not need any instance data from the outer class, and it's also not an anonymous or local class, then you can (and probably should) make the nested class static.
If the second paragraph above did not make sense to you, reread the first paragraph, and try again after you learn about nested and inner classes.
Rakesh shankar wrote:Hi all,
I understood the usage of static modifier wrt variable and methods. For example sqrt is a static method which can be used without creating/instantiating any object.
Likewise, can anyone tell me when do we declare class as static?
You can declare any class as static, whose variables and methods will be used as a common resource, by other classes.
In this way, you don't have to create an instance of a class to use these methods.
Hope this helps.