using System;
/*
////interface////
* Interfaces are used to achieve multiple inheritance in C#.
* Similar to abstract classes, interfaces help us to achieve abstraction in C#.
* Interfaces provide loose coupling - having no or least effect on other parts of code
when we change one part of a code.
*/
/*
* Abstract Class *
*It contains both a declaration and implementation parts.
*Multiple inheritance is not achieved by abstract class.
*It contains a constructor.
*It can contain static members.
*It can contain different types of access modifiers like public, private, protected etc.
*The performance of an abstract class is fast.
*It can be fully, partially, or not implemented.
•
* Interface *
*It contains only the declaration of methods, properties, and events. Since C# 8,
default implementations can also be included.
*Multiple inheritance is achieved by interface.
*It does not contain a constructor.
*It does not contain static members.
*It only contains public access modifier because everything in the interface is public.
*The performance of an interface is slow.
*It should be fully implemented.
*/
public interface Drawable
{
void draw();
void print();
}
public class Rectangle : Drawable
{
public void draw()
{
Console.WriteLine("drawing rectangle...");
}
public void print()
{
Console.WriteLine("Rectangle class");
}
}
public class Circle : Rectangle ,Drawable
{
public new void draw()
{
Console.WriteLine("drawing circle...");
}
}
public class TestInterface
{
public static void Main()
{
Drawable d;
d = new Rectangle();
d.draw();
d = new Circle();
d.draw(); d.print();
}
}