I am wondering how come I can reach inner class directly from outer type as if it is a static member like :
public class Hello {
public class UnderHello
{
void runObject()
{
}
}
}
So when I reach the UnderHello
public class SomeOtherClass {
public void ClickOnMe()
{
Hello.UnderHello //this is shown by auto-complete
}
}
I was expecting something like this :
public class SomeOtherClass {
public void ClickOnMe()
{
Hello world = new Hello();
world.UnderHello // after creating an instance, then UnderHello should now be seen by auto-complete
}
}
If UnderHello was a static class, it would make sense since I can reach static members of a class by directly from Class itself rather than creating instance of the outer class. But it is inner-class.
I am confused.
Can somebody help me now?
Thanks.
Hello.UnderHellois correct, because that is the name of the class.This does not mean, however, that you can actually create instances of this inner class without an instance of the outer class.
The class definition itself is always static, if you will. You do not need an instance to refer to it (and the class definition also does not change with the outer instance).
If
UnderHellowas a field or a method, then yes, you would need an instance to access it, unless it was declaredstatic.