---
title: "What is the difference between an abstract class and an interface?"  
description: "What is the difference between an abstract class and an interface?"  
author: "Mukul Goenka"  
published: 2021-11-14  
updated: 2023-06-06  
canonical: https://www.mindstick.com/interview/33820/what-is-the-difference-between-an-abstract-class-and-an-interface  
category: "c#"  
tags: ["c#", "java", "abstract class", "class", "interface"]  
reading_time: 4 minutes  

---

# What is the difference between an abstract class and an interface?

Let’s us see differences between an abstract class and an interface:

1. Abstract classes are classes that cannot be instantiated ie. that cannot create an object. The interface is like an abstract class because all the methods inside the interface are abstract methods.
2. Surprisingly, abstract classes can have both abstract and non-abstract methods but all the methods of an interface are abstract methods.
3. Since abstract classes can have both abstract and non-abstract methods, we need to use the Abstract keyword to declare abstract methods. But in the interface, there is no such need.
4. An abstract class has constructors while an interface encompasses none.

**Abstract class.**

```
public abstract class Shape{
public abstract void draw();
}
```

**Interface.**

```
public interface Print{
void paint(); // by default public and abstract method, must be override
}
```

## Answers

### Answer by Aryan Kumar

An abstract class and an interface are both object-oriented programming (OOP) constructs that can be used to define the behavior of objects. However, there are some key differences between the two.

- **Abstract classes:** An abstract class is a class that cannot be instantiated directly. Instead, it must be inherited from by another class. This allows you to define common behavior that can be shared by multiple classes. Abstract classes can contain both abstract and non-abstract methods. Abstract methods are methods that do not have a body and must be implemented by the inheriting class. Non-abstract methods can have a body and can be used by both the abstract class and the inheriting class.
- **Interfaces:** An interface is a contract that defines a set of methods that must be implemented by a class. Interfaces cannot contain any data members. This means that interfaces cannot store any data. Interfaces can only contain methods. Methods in an interface are always abstract. This means that they do not have a body and must be implemented by the class that implements the interface.

In general, abstract classes are used when you want to define common behavior that can be shared by multiple classes. Interfaces are used when you want to define a set of methods that must be implemented by a class, but you do not want to store any data.

Here is a table that summarizes the key differences between abstract classes and interfaces:

| Feature | Abstract class | Interface |
| --- | --- | --- |
| Can be instantiated | No | No |
| Can contain data members | Yes | No |
| Can contain methods | Yes | Yes |
| Methods can have bodies | Yes (non-abstract methods) | No |
| Methods must be implemented | Yes (abstract methods) | Yes |
| Used for | Defining common behavior | Defining a set of methods |

### Answer by Mukul Goenka

Let’s us see differences between an abstract class and an interface:

1. Abstract classes are classes that cannot be instantiated ie. that cannot create an object. The interface is like an abstract class because all the methods inside the interface are abstract methods.
2. Surprisingly, abstract classes can have both abstract and non-abstract methods but all the methods of an interface are abstract methods.
3. Since abstract classes can have both abstract and non-abstract methods, we need to use the Abstract keyword to declare abstract methods. But in the interface, there is no such need.
4. An abstract class has constructors while an interface encompasses none.

**Abstract class.**

```
public abstract class Shape{
public abstract void draw();
}
```

**Interface.**

```
public interface Print{
void paint(); // by default public and abstract method, must be override
}
```


---

Original Source: https://www.mindstick.com/interview/33820/what-is-the-difference-between-an-abstract-class-and-an-interface

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
