Exploring Java's Anonymous Classes

Report a typo

Consider the following Java code snippet:


final int x = 10;

SomeInterface si = new SomeInterface() {
    public int method() {
        return x;
    }
};
In this code, an anonymous class is created that implements SomeInterface and accesses a final variable declared in the enclosing scope. Which statements about this code are true?
Select one or more options from the list

Create a free account to access the full topic