Possible Duplicate:
Use of class definitions inside a method in Java
Can we have inner class inside a method ?
Any code sample will be helpful.
Yes you can.
public final class Test {
// In this method.
private void test() {
// With this local variable.
final List<String> localList = new LinkedList<String>();
// We can define a class
class InnerTest {
// Yes you can!!
void method () {
// You can even access local variables but only if they are final.
for ( String s : localList ) {
// Like this.
}
}
}
}
}
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