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();
}
public abstract class AbstractImpl
: AnInterface
{
public AbstractImpl()
{
GetString();
}
}
Posted Mar 31, 2009, 8:54 PM
public abstract class Person
{
private string name;
protected Person(string name)
{
this.name = name;
}
public abstract void Work(); // Requires implementation in a derived class
}
public class Employee : Person
{
private string jobTitle;
public Employee(string jobTitle, string name)
: base(name)
{
this.jobTitle = jobTitle;
}
public override Work() // MUST implement
{
// employee does something in the implementation of Work.
}
}