c# - Interfaces - Implement abstract class methods -
i'm not sure how ask question, want access abstract methods idog. consider this:
static void main(string[] args) { idog dog = new dog(); dog.catchfrisbee(); dog.speak("bark") // error -> no implementation console.readline(); } public class dog : animal, idog { public void catchfrisbee() { console.writeline("dog catching frisbee"); } } public abstract class animal : ianimal { public void speak(string saywhat) { console.writeline(saywhat); } public void die() { console.writeline("no longer exists"); } } public interface idog { void catchfrisbee(); } public interface ianimal { void die(); void speak(string saywhat); }
from static void main, able call dog.speak() can't because it's not implemented in idog. know can access speak() derived classes possible access implemenation or bad design?
assuming idog
s ianimal
s, declare idog
implementing ianimal
public interface idog : ianimal
Comments
Post a Comment