如何创建抽象类和接口的对象 [英] 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< T>
作为类型,但实例本身是 ArrayList< T>
。
You are using the interface type List<T>
as the type, but the instance itself is an ArrayList<T>
.
这篇关于如何创建抽象类和接口的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文