Below code is overriding navigationClick in object GenObject. Is there any other way of overriding navigationClick other than extending GenObject and implementing a method override in sub – class ?
Is there a name for such a construct as below, where an override occurs when the class is initialised ?
GenObject go= new GenObject(){
public boolean navigationClick(int status, int time)
{
No, in order to override a method you always have to create a subclass.
What is done in your example code is called an anonymous class, but it’s really just a shortcut syntax for creating a subclass. At the bytecode level, it’s a class like any other, and it will have its own .class file named something like
ContainingClass$0.class