---
title: "Difference between Interface and Abstract Class in .Net"  
description: "Difference between Interface and Abstract Class in .NetIn this blog, I’m explaining about interface and abstract class  in .NetAbstract ClassAbstract"  
author: "priyanka kushwaha"  
published: 2015-01-23  
updated: 2015-01-23  
canonical: https://www.mindstick.com/blog/730/difference-between-interface-and-abstract-class-in-dot-net  
category: ".net"  
tags: [".net", "abstract class", "interface"]  
reading_time: 3 minutes  

---

# Difference between Interface and Abstract Class in .Net

[Difference between Interface](https://www.mindstick.com/forum/135438/what-is-the-difference-between-interface-and-abstract-class) and [Abstract Class](https://www.mindstick.com/articles/1430/abstract-class) in .Net

In this blog, I’m explaining about [interface and abstract](https://www.mindstick.com/forum/157791/explain-the-difference-between-interface-and-abstract-class-with-examples) class in .Net

## Abstract Class

Abstract class contains incomplete and complete both type of method. It need to extended and implemented. It cannot be instantiated.

Abstract Class have the following feathers.

1. An abstract class cannot be instantiated.

2. An abstract class contain abstract members [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) non abstract member .

3. An [abstract method](https://www.mindstick.com/articles/23305/abstract-methods-and-class-in-c-sharp) is implicitly a [virtual method](https://www.mindstick.com/forum/157796/what-is-a-virtual-method-in-c-sharp-also-give-a-suitable-example).

4. It is an error to use the abstract modifier or static property.

5. An abstract class can has constructor.

6. An abstract class cannot be inherited by structures.

## Example:

Namespace AbstractClass

{

public abstract class BaseClass

{public BaseClass(string msg)

{

System.Console.WriteLine(msg);

}

public void display(double res)

{

System.Console.WriteLine("Result="+res);

}

abstract public double sum(double var1, double var2);

}

public class DriveClass:BaseClass

{

public DriveClass() : base("this is [base class](https://www.mindstick.com/blog/116/base-class-initilization)")

{}

public override double sum(double var1, double var2)

{

return (var1 + var2);

}

}

class Program

{

[static void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) Main(string[] args)

{

DriveClass objcs = new DriveClass();

double var1,var2;

Console.WriteLine("Enter first no.");

var1=Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Enter Second no.");

var2 = Convert.ToDouble(Console.ReadLine());

double result=objcs.sum(var1,var2);

objcs.display(result);

}

}

}

class Program

{

static void Main(string[] args){

DriveClass objcs = new DriveClass();

double var1,var2;

Console.WriteLine("Enter first no.");

var1=Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Enter Second no.");

var2 = Convert.ToDouble(Console.ReadLine());

double result=objcs.sum(var1,var2);

objcs.display(result);

}

}

}

## Interface

An interface contains only prototype of method, properties, events or indexers. It has no [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp). Implementation of the methods is done by the class that which implements the interface.

## Properties of interface

1. Interface must be declared with the key word ‘interface’.

2. It contains only incomplete method.

3. Interface does provides facility for [multiple inheritance](https://www.mindstick.com/forum/159471/how-does-c-plus-plus-support-multiple-inheritance-and-what-are-potential-issues-associated-with-it).

4. Interface can not contains constructors.

5. Member of interface cannot be static.

## Create an Interface Class

namespace InterfaceApplication

{

interface ICircle

{

double Area(double radius);

}

interface IRectangle

{

double Area(double length, double breadth);

}

interface ITriangle

{

double Area(double basee, double height);

}

## Example of interface

namespace InterfaceApplication

{

public class InheritClass : ICircle,IRectangle,ITriangle

{

public void Print(string msg)

{

MessageBox.Show(msg);

}

double ICircle.Area(double radius)

{

return (3.14 * radius * radius);

}

double IRectangle.Area(double length, double breadth)

{

return (length * breadth);

}

double ITriangle.Area(double basee, double height)

{

return (basee * height);

}

}

}

namespace InterfaceApplication

{

public partial class RectangleFrom : Form

{

public RectangleFrom()

{

InitializeComponent();

}

private void btnSubmit_Click(object sender, EventArgs e)

{

txtArea.Enabled = true;

IRectangle objRect = new InheritClass();

Doublearea= objRect.Area(Convert.ToDouble(txtLength.Text), Convert.ToDouble(txtWidth.Text));

txtArea.Text = area.ToString();

}

}

}

namespace InterfaceApplication

{

public partial class CircleForm : Form

{

public CircleForm()

{

InitializeComponent();

}

private void bntSubmit_Click(object sender, EventArgs e)

{

txtArea.Enabled =true ;

ICircle objInteritClass = new InheritClass();

double radius =objInteritClass.Area(Convert.ToDouble(txtRadius.Text));

txtArea.Text = radius.ToString();

}

}}

namespace InterfaceApplication

{

public partial class TriangleForm : Form

{

public TriangleForm()

{

InitializeComponent();

}

private void btnSubmit_Click(object sender, EventArgs e)

{

lblTriArea.Enabled = true;

ITriangle objInheritClass = new InheritClass();

Double area=objInheritClass.Area(Convert.ToDouble(txtBase.Text), Convert.ToDouble(txtHeight.Text));

txtArea.Text = area.ToString();

}

}

}

namespace InterfaceApplication

{

public partial class InterfaceForm : Form

{

public InterfaceForm()

{

InitializeComponent();

}

private void btnCircle_Click(object sender, EventArgs e)

{

CircleForm objCircleForm = new CircleForm();

objCircleForm.Show();

}

private void btnRectangle_Click(object sender, EventArgs e)

{

RectangleFrom objCircleForm = new RectangleFrom();

objCircleForm.Show();

}

private void btnTriangle_Click(object sender, EventArgs e)

{

TriangleForm objTriangleForm = new TriangleForm();

objTriangleForm.Show();

}

}

}

---

Original Source: https://www.mindstick.com/blog/730/difference-between-interface-and-abstract-class-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
