How to create an object of an abstract class and interface

前端 未结 12 1216
旧巷少年郎
旧巷少年郎 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:19

    What you know is correct. You cannot create an object of abstract class or interface since they are incomplete class (interface is not even considered as a class.)

    What you can do is to implement a subclass of abstract class which, of course, must not be abstract. For interface, you must create a class which implement the interface and implement bodies of interface methods.

    Here are orginal tutorial on oracle site, http://download.oracle.com/javase/tutorial/java/IandI/abstract.html and http://download.oracle.com/javase/tutorial/java/concepts/interface.html

提交回复
热议问题