Need a bit of help understanding anonymous classes

I want to rewrite the following code using an anonymous class. The code is using local inner class. So say I have coding like this


public B f(){ return new myLocalClass();

 class MyLocalClass extends B{
    
     private int x;
     private String s;

     public MyLocalClass(){
       super(18.5,7);
       x=1;
       s = new String ("dog")
      }
     
      public String g() { return ("cat") }
  }


}


I don’t know why but I can quite grasp the concept of anonymous classes. How exactly would I convert this code to an anonymous class. It might help me a bit understand it.

I’m not sure if this is correct


public B f(){ return new B();

   {
   private int x;
   private String s;
   super(18.5,7);
   x = 1;
   s = new String("dog")
   }
   
    public String g(){ return ("cat") }

}


Would this be the anonymous class equivalent?

No.

Read this