Is it legal to define a new anonymous class inside a method, and then assign an instance to an outer class private field, like commented in the code below? I am learning Java and trying to get my head around the reason behind this. Thanks!

```
public class Outer{
    private int id;
    private String name;
    private SwingWorker doSomething; //Is it ok not to include it in the constructor?  
 public Outer (int id, String name){

    //constructor, but didn't include the instance doSomething
 }
 public void fuctionOne(){
    Swingworker doSomething =new SwingWorker<int, Void>(){
        protected int DoInBackground(){
          ...........// created an anonymous class and override methods 

```