Informatica Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Phone Interview
It depends on the desing. Map interface contains Entry inner static interface .. which means Entry interface is not in need of accessing Map Interface instance members.. So if we want to restrict our inner class not to access instance members of outer class, then definitely we would make our inner class as static inner class..
Taking a scenario in consideration:
class Traveler
{
int age;
...
static class Meal
{
int type;
...
}
}
2 reasons:
a) Because class Meal is only to be used by Traveler class. So, no need to make it a top-level class.
a) better encapsulation (Here, Meal class does not require access to the non-static members of class Traveler).
You don't absolutely have to have them. They're convenient because they allow you to use a helper class without exposing the helper class to the outside world. It's a form of information hiding.
- eugene.yarovoi June 15, 2012