Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how add method of list interface works when there is no body for it? where is the add method of list interface defined?

What I have tried:

how add method of list interface works when there is no body for it? where is the add method of list interface defined?
Posted
Updated 22-May-18 4:15am

1 solution

List is an Interface, not a class, and so cannot define the body of any method - it defines the method signatures (what the methods must input and output) but cannot define any implementation of the code. When a concrete class adds an Interface, it must provide implementations of all the method signatures that were defined by the interface definition.

Similarly, you can't create an instance of an Interface - you can only create instances of the classes that implement the Interface. But you can declare a variable of the Interface type, and it can contain any object which implements that Interface.
When you try to use the Add method the framework works out what type of object is in the variable at run time, and calls the appropriate version of the Add method that was defined in that class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900