Results 1 to 2 of 2

Thread: Inherit multiple interfaces with conflicting method names

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Answers
    3

    Inherit multiple interfaces with conflicting method names

    What happens if you inherit multiple interfaces and they have conflicting method names?

    interface IA
    {
    void sing(string song);
    }

    interface IB
    {
    void sing(string prayer);
    }

    Describe the implementation of the following class

    class singer: IA, IB

    How can I declare different methods for both interfaces and call them differently at runtime?


  2. #2
    Junior Member
    Join Date
    Apr 2008
    Answers
    1

    Re: Inherit multiple interfaces with conflicting method names

    look for this code

    interface IA
    {
    void sing(string song);
    }

    interface IB
    {
    void sing(string prayer);
    }

    class singer: IA, IB
    {
    void IA.sing(string song)
    {
    Console.WriteLine("From interface IA "+song);
    }

    void IB.sing(string song)
    {
    Console.WriteLine("From interface IB "+song);
    }

    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact