---
title: "Difference between Abstract Class and Interface with example."  
description: "Difference between Abstract Class and Interface with example."  
author: "Anubhav Sharma"  
published: 2025-06-10  
updated: 2025-06-12  
canonical: https://www.mindstick.com/forum/161702/difference-between-abstract-class-and-interface-with-example  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Difference between Abstract Class and Interface with example.

**[Difference between Abstract](https://www.mindstick.com/forum/158922/describe-the-difference-between-abstract-classes-and-interfaces-in-c-sharp) [Class and Interface](https://www.mindstick.com/forum/23098/difference-between-abstract-class-and-interface-in-java) with example.**

## Replies

### Reply by ICSM Computer

> Both **abstract classes** and **interfaces** define **contracts** for other classes to implement, but they differ in **capabilities, design purpose, and usage**.

## Quick Comparison Table

| Feature | **[Abstract Class](https://www.mindstick.com/articles/1430/abstract-class)** | **[Interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces)** |
| --- | --- | --- |
| Inheritance | One abstract class per class (single inheritance) | Multiple interfaces can be implemented |
| Members | Fields, constructors, methods, properties | Only method/property signatures (no fields) |
| Method implementation | Can have implemented & abstract methods | C# 8.0+: Can have default methods |
| Access modifiers | Yes (public, protected, etc.) | All members are public by default |
| Constructors | Yes | No constructors |
| Use case | Common base with shared code | Only contract definition (pure abstraction) |
| Performance/Size | Slightly heavier | Lightweight |

## Example: Abstract Class

```cs
public abstract class Animal
{
    public string Name { get; set; }

    public void Eat()
    {
        Console.WriteLine("Animal is eating");
    }

    public abstract void MakeSound(); // must be implemented in derived class
}

public class Dog : Animal
{
    public override void MakeSound()
    {
        Console.WriteLine("Bark!");
    }
}
```

### Usage:

```cs
Animal dog = new Dog();
dog.Eat();        // Inherited concrete method
dog.MakeSound();  // Overridden method
```

## Example: Interface

```cs
public interface IPlayable
{
    void Play();
}

public interface IStoppable
{
    void Stop();
}

public class MediaPlayer : IPlayable, IStoppable
{
    public void Play() => Console.WriteLine("Playing...");
    public void Stop() => Console.WriteLine("Stopped.");
}
```

### Usage:

```cs
IPlayable player = new MediaPlayer();
player.Play();
```

## When to Use What?

| Scenario | Use |
| --- | --- |
| Need to provide base functionality | Abstract class |
| Need to support multiple base types | Interface |
| Design a plug-in system or API contract | Interface |
| Need constructors or fields | Abstract class |
| Want to share default code | Abstract class (or C# 8+ interfaces) |

## Tip

- Use **interface** when you only need **contract/behavior**
- Use **abstract class** when you need to **share logic and structure**


---

Original Source: https://www.mindstick.com/forum/161702/difference-between-abstract-class-and-interface-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
