Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
5
Reply
Why is there a need to re-declare a method as "abstract" in an abstract class inheriting an interface
Sherif Ahmed
Mar 31 2009 2:15 PM
3.8k
Reply
I have a basic C# question that I thought I’d seek your help on. In Java the following class structure is legitimate (and makes logical sense as AddInterfaceImpl is an abstract class and should not be obligated to implement all methods from the Interface it implements). However the equivalent C# code throws error indicating that AddInterfaceImpl does not implement all the methods of the underlying interface). C# forces me to declare GetString() as an abstract method in AddInterfaceImpl to avoid compiler errors. Does someone have a logical reason as to why GetString() has to be re-declared as Abstract in the AddInterfaceImpl class ? Java Code (Legal) public interface AnInterface { public String GetString(); } public abstract class AnInterfaceImpl implements AnInterface { public AnInterfaceImpl() { GetString(); } } C# Equivalent interface AnInterface { string GetString(); } //Will Throw compilation error // GetString has to be declared in AbstractImpl as string abstract GetString() in order to avoid compiler errors public abstract class AbstractImpl : AnInterface { public AbstractImpl() { GetString(); } }
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
5
)
Next Recommended Forum
how to stop dragging window with titlebar
Printing Cyrstal report from button