Inheritance with interface

Asked

Viewed 161 times

4

How could I solve the following problem.

Setting: I have a class B that inherits from class A and implements interface I.

Problem: The I interface requires the implementation of the X method which in turn is implemented in class A, and not in B.

Visual Studio does not recognize this implementation by the father, what I should do?

  • 2

    If B inherits from A, the method is implemented in A, there is no way it does not exist in B. You can give more information, post the code?

  • 1

    Yes, the method is in B but it does not recognize this method in the implementation of the I interface.

  • 3

    Does the method have the same signature (same parameters, identical declaration)? Post the code of A, B and I.

  • 3

    It was my mistake, the interface was receiving, as parameter, an int? and not an int. Thanks for the help.

  • 1

    @bfavaretto, because you put it on hold?

  • 1

    @Harrypotter Because of the author’s comment just above. He made an error in the interface, which does not appear in the question as it does not include the code.

  • 3

    @bfavaretto is under discussion at the goal: http://meta.pt.stackoverflow.com/q/1527/6026

  • Just for the record, one of those open votes is mine, and I clicked wrong when trying to click the inheritance tag. I don’t agree with the opening.

Show 3 more comments

1 answer

7


Setting:

public class B: A
{

}
public class A: I
{

    public object X
    {
        get;
        set;
    }
}
public interface I
{
    object X { get; set; }
}

Using:

B b = new B();
b.X = 10;

That is to say, B inherited all behavior from A, even having a contract with I, then, B also owns the X.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.