Suppose I have an interface as defined below:
public interface IFunctionality { void Method(); }
and I implement this interface for an abstract class, as shown below:
public abstract class AbstractFunctionality: IFunctionality { public void Method() { Console.WriteLine("Abstract stuff" + "\n"); } }
again, I have a specific class that inherits from an abstract class, as shown below:
public class ConcreteFunctionality: AbstractFunctionality { public void Method() { Console.WriteLine("Concrete stuff" + "\n"); } }
Now I have the following code,
ConcreteFunctionality mostDerived = new ConcreteFunctionality(); AbstractFunctionality baseInst = mostDerived; IFunctionality interfaceInst = mostDerived; mostDerived.Method(); baseInst.Method(); interfaceInst.Method();
The result that I get after doing this material is as follows.
Concrete stuff Abstract stuff Abstract stuff
But what I expected the output would be "Concrete Stuff" in all three cases, because what I am doing here assigns the ConcreteFunctionality reference to variables of type AbstractFunctionality and IFunctionality .
What is happening inside the country. Please clarify.
c # oop interface abstract-class concrete
Vikram Jan 25 '13 at 7:03 2013-01-25 07:03
source share