Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can not instantiate an abstract class or an interface - you can instantiate one of their subclasses/implementers.

Examples of such a thing are typical in the use of Java Collections.

List<String> stringList = new ArrayList<String>();

You are using the interface type List<T> as the type, but the instance itself is an ArrayList<T>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...