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:osHow 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:osYou 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>
.