如何在java中的静态类中声明内部类的对象?
public class xyz
{
static class abc
{
...
// I want to declare an object of class a here. how can I do this?
}
class a
{
...
}
}
答案 0 :(得分:2)
内部类的实例存在于封闭类的实例的上下文中。因此,您必须首先创建封闭类的实例,然后您可以从中创建内部类的实例。例如:
public class xyz {
static class abc {
a member = new xyz().new a();
}
class a {
}
}