In traditional textbooks or books, we will instill a concept that abstract classes can be inherited (extends), interfaces can be implemented (implements), but abstract classes cannot be implemented (implements ), the interface cannot be inherited (extends), but today's point of view has been overturned.
Abstract classes can be inherited (extends), interfaces can be implemented (implements), but abstract classes cannot be implemented (implements). There are no problems with these three ideas, but the interface can be inherited. Of course, you may give an example similar to the following to prove that the interface cannot be inherited,CodeAs follows:
Indeed, the above Code cannot be compiled and the following error occurs:
You may want to use the above example to prove that my opinion is incorrect, but please refer to the following example:
Look at the highlighted part of the code in the figure. It can be compiled. The following compilation result:
In addition, I also did tests in C #, because the implementation and inheritance in C # cannot be seen from the implements or extends keywords similar to Java. They are all reflected by the: symbol, however, you can see the specific code. See the following code:
Using System;
Using System. Collections. Generic;
Using system. text;
namespace day2
{< br> interface interfacea
{< br> int Add ();
}
interface interfaceb: interfacea
{< br> int minus ();
}< BR >}< br>
the code can be compiled in.
the preceding example shows that interfaces can be inherited, that is, interface expansion, in this way, the class that inherits an interface has two interface methods.
conclusion: interfaces can inherit interfaces, and classes can only implement interfaces.