如何创建抽象类和接口的对象 [英] How to create an object of an abstract class and interface
本文介绍了如何创建抽象类和接口的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建抽象类和接口的对象?我知道我们不能直接实例化抽象类的对象.
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.
推荐答案
您不能实例化抽象类或接口 - 您可以实例化它们的一个子类/实现器.
You can not instantiate an abstract class or an interface - you can instantiate one of their subclasses/implementers.
这种事情的例子在 Java 集合的使用中很典型.
Examples of such a thing are typical in the use of Java Collections.
List<String> stringList = new ArrayList<String>();
您使用接口类型 List
作为类型,但实例本身是 ArrayList
.
You are using the interface type List<T>
as the type, but the instance itself is an ArrayList<T>
.
这篇关于如何创建抽象类和接口的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文