Reputation: 23
How can I declare an object of an inner class inside a static class in java?
public class xyz
{
static class abc
{
...
// I want to declare an object of class a here. how can I do this?
}
class a
{
...
}
}
Upvotes: 1
Views: 126
Reputation: 206786
Instances of inner classes exist in the context of an instance of the enclosing class. So you must first create an instance of the enclosing class, and from there you can create an instance of the inner class. For example:
public class xyz {
static class abc {
a member = new xyz().new a();
}
class a {
}
}
More information: Oracle Java Tutorials - Nested Classes
Upvotes: 2