How to create an object of an abstract class and interface

前端 未结 12 1213
旧巷少年郎
旧巷少年郎 2020-12-09 04:36

How do I create an object of an abstract class and interface? I know we can\'t instantiate an object of an abstract class directly.

12条回答
  •  不思量自难忘°
    2020-12-09 05:23

    There are two ways you can achieve this.

    1) Either you extend / implement the Abstract class / interface in a new class, create the object of this new class and then use this object as per your need.

    2) The Compiler allows you to create anonymous objects of the interfaces in your code.

    For eg. ( new Runnable() { ... } );

    Hope this helps.

    Regards, Mahendra Liya.

提交回复
热议问题