---
title: "What is the difference between override, new, and virtual keywords?"  
description: "What is the difference between override, new, and virtual keywords?"  
author: "Anubhav Sharma"  
published: 2025-06-19  
updated: 2025-06-24  
canonical: https://www.mindstick.com/forum/161730/what-is-the-difference-between-override-new-and-virtual-keywords  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# What is the difference between override, new, and virtual keywords?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between `override`, `new`, and `virtual` [keywords](https://www.mindstick.com/articles/12899/how-to-spot-if-you-re-optimizing-for-the-wrong-keywords)?

## Replies

### Reply by Ponu Maurya

In C#, the `virtual`, `override`, and `new` keywords are used for method overriding and hiding in object-oriented inheritance. Here's a breakdown of each:

## `virtual`

- Used in a **base class** to indicate that a method or property **can be overridden** in a derived class.
- Allows **runtime polymorphism**.

```cs
public class Base
{
    public virtual void Show()
    {
        Console.WriteLine("Base Show");
    }
}
```

## `override`

- Used in a **derived class** to **override a virtual** method or property from a base class.
- The base class must mark the member as `virtual`, `abstract`, or `override`.

```cs
public class Derived : Base
{
    public override void Show()
    {
        Console.WriteLine("Derived Show");
    }
}
```

## `new`

- Used to **hide** a base class member **without overriding** it.
- Does **not support polymorphism** — the method called depends on the **reference type**, not the object type.

```cs
public class Derived : Base
{
    public new void Show()
    {
        Console.WriteLine("Derived Show (new)");
    }
}
```

## Example to Illustrate the Difference

```cs
Base obj = new Derived();
obj.Show(); // What gets called?
```

### Output:

- If `Show()` is overridden using `override`, output: `"Derived Show"`
- If `Show()` is hidden using `new`, output: `"Base Show"` (because `obj` is a `Base` reference)

## Summary Table

| Keyword | Where Used | Purpose | Supports Polymorphism? |
| --- | --- | --- | --- |
| `virtual` | Base class | Marks a method as overridable | Yes |
| `override` | Derived class | Overrides a virtual/abstract method | Yes |
| `new` | Derived class | Hides base class method (not override) | No |


---

Original Source: https://www.mindstick.com/forum/161730/what-is-the-difference-between-override-new-and-virtual-keywords

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
