abstract class - Java: new AbstractClass(){} What is this declaration called? -


in application there abstract class used multiple time follows:

public class myclass{     int amount;     string name;     public void printresultsfromdb(){         new myabstractclass(name){             @override             string getdatafromdb(){                 //some implementation             }         };     } }  public abstract myabstractclass{     string name;     public myabstractclass(string name){         this.name = name;     }     abstract string getdatafromdb();     void execute(){         //some implementation     } } 

i want know line number 5 in code called? know cannot instantiate abstract class. declaration called anonymous class?

it anonymous class allow implement interface.

from oracle docs:

the anonymous class expression consists of following:

  • the new operator
  • the name of interface implement or class extend. in example, anonymous class implementing interface
    helloworld.
  • parentheses contain arguments constructor, normal class instance creation expression. note: when implement interface, there no constructor, use empty pair of parentheses, in example.
  • a body, class declaration body. more specifically, in body, method declarations allowed statements not.

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -