Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Is there a way to do this?

RiddickRiddick Posts: 41Member
Suppose we have an interface I with one method, call it method(). We have class A that implements the interface, and a class B that derive from A. Both classes decide to hidde the implementation of the interface. How can a method of class B, lets call it ShowUpperMethod(), can call method() in A

PD> Here is the code to help understand... :) thx.

namespace ExplicitImplementation
{
public interface I
{
void method ();
}

public class A : I
{
void I.method ()
{
Console.WriteLine ("Im class A implementing interface...");
}
}

public class B : A, I
{
public void ShowUpperMethod ()
{
// I want to call the method() in the upper class.
}

void I.method ()
{
Console.WriteLine ("Im class B implementing interface...");
}
}
}

Comments

  • SoEnLionSoEnLion Posts: 7Member
    This code may help you. To call an upper method you can use the key word "base".


    namespace ConsoleApplication1
    {
    class Program
    {

    public static void Main(string[] args)
    {
    A expA = new A();
    B expB = new B();

    expA.method();
    expB.ShowUpperMethod();
    expB.method();
    Console.ReadKey();

    }
    }

    public interface I
    {
    void method();
    }

    public class A : I
    {
    public void method()
    {
    Console.WriteLine("Im class A implementing interface...");
    }
    }

    public class B : A, I
    {
    public void ShowUpperMethod()
    {
    base.method();
    }

    public void method()
    {
    Console.WriteLine("Im class B implementing interface...");
    }
    }
    }
  • SoEnLionSoEnLion Posts: 7Member
    This post has been deleted.
  • RiddickRiddick Posts: 41Member
    Ok, I understand that part. However, I wanted the methods to be hiden in both clases. Like I showed before:

    void I.method ()

    See the example that I had there.

    Any clue? I mean I haven't figure out.
  • RiddickRiddick Posts: 41Member
    This post has been deleted.
  • RiddickRiddick Posts: 41Member
    This post has been deleted.
Sign In or Register to comment.