I am creating an Object as a class variable with anonymous type. There are no compilation errors. My question is how to use the class? How to call the methods that I am defining? Where is it used actually?
public class MyClass {
Object o = new Object(){
public void myMethod(){
System.out.println("In my method");
}
};
}
I am not able to call the myMethod()
of object o. How to do that and when do we use this?