Experienced product developers,web developers and gurus in this forum ,kindly share your experiences.
3 Answers
static class : top level class can't be declared as static. Only Member and Nested top-level classes can be defined as static.
You declare member classes when you want to use variables and methods of the containing class without explicit delegation. When you declare a member class, you can instantiate that member class only within the context of an object of the outer class in which this member class is declared. If you want to remove this restriction, you declare the member class a static class.When you declare a member class with a static modifier, it becomes a nested top-level class and can be used as a normal top-level class as explained above.
nested top-level class is a member classes with a static modifier. A nested top-level class is just like any other top-level class except that it is declared within another class or interface. Nested top-level classes are typically used as a convenient way to group related classes without creating a new package.
static methods : mostly for utility to be shared across instances/application. A good example of this are the many utility methods in the predefined Math class
static variables : information to be shared amongst instances. Mostly used as constants.
2 Comments
static variables: when ever you need to have a variable in your class for all instances. this variable will be shared between instances.
static class: i usually try to avoid static classes and use singleton instead. (inner classes are exception: if you don't need to access to outer class variables its better to make your inner class static)