I have seen an unusual occurrence. Please help me how to instantiate a class which is written inside a method. The below program compiled successfully in Netbeans
class OuterClass
{
int instanceVar;
void InstanceMethod()
{
class InnerClass
{
int innerClassVar;
}
}
}
just do it like any other object:
class OuterClass
{
int instanceVar;
void InstanceMethod()
{
class InnerClass
{
int innerClassVar;
}
//...
InnerClass myInstance = new InnerClass();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With