Results 1 to 5 of 5

Thread: Multiple Implementation of an Interface in C#

  1. #1
    Join Date
    Sep 2010
    Posts
    38

    Multiple Implementation of an Interface in C#

    Hello guys, I am having a bit in problem in multiple implementation of Interface in C#. I don’t know whenever I try it understand this term it makes me confused. I tried it twice but still I am not able to understand. Does anyone know any example of multiple implementation of an interface? If, anyone having any idea or knowledge about this particular topic than please let me know.

  2. #2
    Join Date
    May 2009
    Posts
    527

    Re: Multiple Implementation of an Interface in C#

    Before implementing interface, one must know how an interface is defined and declared. An interface can contain one or more methods, properties, indexers, and events but none of them are implemented in the interface. Syntax - Interface Interface Name { Member declarations; }
    The accessibility of an interface can be controlled by using the modifiers public, protected, internal and private. The use of a particular modifier depends on the contact in which the interface declaration occurs.

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: Multiple Implementation of an Interface in C#

    We can implement multiple interface in C sharp which is also available. Using interface one can also define multiple inheritance in C sharp. You can get understand this concept with help of this example.
    using System;
    interface Additon
    { int Add(); }
    interface Multiplication
    { int mul(); }
    class Computation : Addition, Multiplication

    { int x,y;
    public Computation(int x, int y)
    { this.x = x; this.y = y; }
    public int Add()
    { return(x+y); }
    public int Mul()
    { return(x*y) }
    }
    class Test
    {
    public static void Main()
    { Computation com = new Compution (10,20);
    Addition add = (Addition) com;
    Console.WriteLine(“Sum = “ + add.Add());
    Multiplication mul = (Multiplication) com;
    Console.WriteLine(“Product = “ +mul.Mul()); }
    }

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: Multiple Implementation of an Interface in C#

    There is option of multiple implementation of an interface also. This also achieved in C sharp. The following example illustrates the multiple implementations of interface.
    using System;
    interface Area
    { double Compute(double x); }
    class Square : Area
    {
    public double Compute(double x)
    { return(x*x); }
    }
    class Circle : Area
    {
    public double Compute(double x)
    { return(Math.PI * x * x); }
    }
    class InterfaceTest2
    {
    public static void Main()
    { Square sqr = new Square ();
    Circle cir = new Circle ();
    Area area; area = sqr as Area;
    Console.WriteLine("Area of square = " +area.Compute (10.0));
    area = cir as Area ;
    Console.WriteLine ("Area of Circle = "+ area.Compute (10.0));
    }
    }

  5. #5
    Join Date
    Apr 2009
    Posts
    569

    Re: Multiple Implementation of an Interface in C#

    Usually interfaces are defined to get multiple inheritance done C sharp. As C sharp is an object oriented programming language. So, it does not support multiple inheritance but with the help of inheritance one can achieve that. Interface is used in C sharp quite frequently. Though C sharp does not support multiple inheritance but this is achieved with the help of only inheritance. I think that this concept is one the important concept in c sharp.

Similar Threads

  1. Replies: 7
    Last Post: 22-10-2011, 10:35 PM
  2. Replies: 1
    Last Post: 02-12-2010, 08:01 AM
  3. Implementation of mkfifo() : C
    By Garett in forum Software Development
    Replies: 4
    Last Post: 02-02-2010, 07:27 PM
  4. Implementation of mkdir() : C
    By Agustíne in forum Software Development
    Replies: 4
    Last Post: 02-02-2010, 06:16 PM
  5. Replies: 3
    Last Post: 19-11-2009, 09:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,317,318.21587 seconds with 17 queries