[Solved] how list methods work? [duplicate]


List<Book> list

Here list is a reference to an object, not an object itself. When you call interface methods on this reference, you are actually calling the overridden methods of some concrete class that this reference points to.

To illustrate

List<Book> list = new List<Book>(); //Illegal
List<Book> list = new ArrayList<Book>(); //legal ArrayList is a concrete implementation of list.

That is the power of interfaces, I can do stuff with this reference without worrying about how it works or how it is implemented.

solved how list methods work? [duplicate]