+ 4

C# ..... Can we override public method of interface. In a class which implements that interface.??

Can we override public method of interface. In a class which implements that interface or if we do it just hides the logic of public method of that interface.?in c#

20th Mar 2020, 2:01 PM
Smit Kalkani
Smit Kalkani - avatar
3 Respostas
+ 3
Smit Kalkani This is an example in Java and considering that C# is pretty much similar, I have written this basic code for your understanding. Interface methods are by default abstract and public. So if a class is implementing an interface and giving implementation to the interface method than it should also declare the method as 'public' because you cannot assign weaker access specifiers to a public method or else it will throw an error. I have also mentioned an extra class which extends the class which has implemented the interface to show that it works too. https://code.sololearn.com/c9FU142don72/?ref=app
20th Mar 2020, 2:31 PM
Avinesh
Avinesh - avatar
+ 3
https://code.sololearn.com/c5VYQiS3TY9g/?ref=app
20th Mar 2020, 3:23 PM
Smit Kalkani
Smit Kalkani - avatar
+ 3
I got my ans in java default method with implementation is inherited in base class where in c# public method with logic implementation is not inherited in base class. Am I right?
20th Mar 2020, 3:25 PM
Smit Kalkani
Smit Kalkani - avatar