vs interface
The difference between an interface and an abstract class. The callable permission of the interface, which is the default public, cannot specify other callable permissions, the attributes, domains, methods of the abstract class are implemented with derived classes, and not necessarily all implementations, interfaces are implemented with class implementations of interfaces, and all members of an interface declaration must be implemented; An instance of a class that implements an interface is cast over, and called as an instance of a class, an abstract class cannot have an instance.
- Interface
- Are declarations, projects include properties and methods, implemented with classes.
interface iperson{int age; Addage () {}}
- With the class implementation, all projects of the interface must be implemented.
Class person:iperson{private int age; Age () {get} {return age; }} addage () {age++; }}
- Classes can implement multiple interfaces, multiple interfaces separated by commas, and all items that must implement an interface.
Class Person:iperson, ianimal{}
- Derived classes can also implement interfaces separated by commas from the parent class and interface. The base class has been implemented, and the derived class inherits the implementation
Class Person:animal, IPerson {}
- When a class implements multiple interfaces that have the same name as an item,
You need to specify which interface of the project is implemented. When using an object, you must first create an object that implements the interface, and then cast the object into an interface, using the properties and methods of the interface. When a class has implemented an interface with the same name method, the next implementation defaults to another, and the same is true when the object is used. interface iperson{int age; }interface ianimal{int age; }class Person:iperson, ianimal{iperson.age () {} ianimal.age () {}} Create Myunit object IPerson Myiperson = (IPerson) myunitmyiperson.age
- Use new to hide the implementation of the base class
New Age
c#-interface