C # For interface implementation, display implementation interface, and inheritance,
First, list the code I wrote:
Interfaces, abstract classes, and implementation classes
public interface IA { void H(); } public interface IB { void H(); } public abstract class D { public abstract void H(); } public class C : D,IA, IB { void IA.H() { Console.WriteLine("all a.h"); } public override void H()//T { Console.WriteLine("all b.h"); } }
If Class C inherits the abstract class D, you can use the override keyword in Class C. The method H (T location) that the interface IB calls is also overwritten) [I can understand the T-position method. H colleagues overwrite method H in abstract class D and method H in interface IB ].
If Class C does not inherit the abstract class D, the override keyword cannot be used in Class C. The override keyword can only be used when the abstract class is inherited (this is what I feel after using it ).
The initial code is as follows:
public interface IA { void H(); } public interface IB { void H(); } public abstract class D { public abstract void H(); } public class C : D,IA, IB { public override void H() { Console.WriteLine("all h"); } void IA.H() { Console.WriteLine("all a.h"); } void IB.H() { Console.WriteLine("all b.h"); } }
Display implementation interface. When displaying the implementation interface, you cannot use the access permission keyword [private, protected, public, etc.] On the covered methods or fields]
If the abstract class D is not inherited:
public class C : IA, IB { public void H()//U { Console.WriteLine("all h"); } void IA.H() { Console.WriteLine("all a.h"); } void IB.H() { Console.WriteLine("all b.h"); } }
During the call, the interface IA object can only access IA. H (), interface IB can only access IB. H (), and the method that cannot access the U location. The method H at the U location can be accessed only when class C is instantiated.
Call code:
class Program { static void Main(string[] args) { IA a = new C(); IB b = new C(); a.H(); b.H(); D d = new C(); d.H(); C c = new C(); c.H(); Console.WriteLine("Hello World!"); Console.ReadLine(); } }
The above is my personal summary. If you have any mistakes, please correct them. Your language is not good. Welcome to criticism.