0

I have the following code. (in c#) interface 1:

public interface iBclass
{
   int addition(int a);

   int s(); //and more methods from this ......


}

interface 2:

 public interface iAclass
 {
    int addition(int a);
    //more methods.....
 }

Class that inherits both interfaces:

public class dClass : iAclass , iBclass
{

    int iAclass.addition(int a)
    {
        return 0;
    }

   int iBclass.addition(int a)
    {
        return 1;
    }


   public int s()
   {
       return 3;
   }
}

the problem is i am not able to access the Method iAclass.addition(int a) and iBclass.addition(int a) with the d object.

  dClass d = new dClass();

how can i access those method by 'd' object? and why those interface methods are not allow to define as public?

4
  • looks like you don't really need IAclass Commented Feb 24, 2014 at 12:22
  • @markg : my IAclass having extra functions that are not present in the IBclass then? Commented Feb 24, 2014 at 12:23
  • By default it is private right? Commented Feb 24, 2014 at 12:26
  • @ssilas777: yes.i need return type. void allows the public declaration. but if you add some return type to it then public is not allowed. Commented Feb 24, 2014 at 12:29

1 Answer 1

3

The interfaces are implemented explicitly. So you can only call them by using the interface:

dClass d = new dClass();
iAclass a = (iAclass)d;
a.addition(123);  // Calls implementation for iAclass
iBclass b = (iBclass)d;
b.addition(123);  // Calls implementation for iBclass

See this link for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.