Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
Difference Between List and Set in C#
Next article icon

Difference between Abstract Class and Interface in C#

Last Updated : 17 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

An abstract class is a way to achieve abstraction in C#.

To declare an abstract class, we use the abstract keyword. An Abstract class is never intended to be instantiated directly. This class must contain at least one abstract method, which is marked by the keyword or modifier abstract in the class definition. The Abstract classes are typically used to define a base class in the class hierarchy. 

Example: 

CSharp




// C# program to illustrate the
// concept of abstract class
using System;
 
// abstract class 'G'
public abstract class G {
 
    // abstract method 'gfg1()'
    public abstract void gfg1();
}
 
// class 'G' inherit
// in child class 'G1'
public class G1 : G {
 
    // abstract method 'gfg1()'
    // declare here with
    // 'override' keyword
    public override void gfg1()
    {
        Console.WriteLine("Class name is G1");
    }
}
 
// class 'G' inherit in
// another child class 'G2'
public class G2 : G {
 
    // same as the previous class
    public override void gfg1()
    {
        Console.WriteLine("Class name is  G2");
    }
}
 
// Driver Class
public class main_method {
 
    // Main Method
    public static void Main()
    {
 
        // 'obj' is object of class
        // 'G' class '
        // G' cannot
        // be instantiate
        G obj;
 
        // instantiate class 'G1'
        obj = new G1();
 
        // call 'gfg1()' of class 'G1'
        obj.gfg1();
 
        // instantiate class 'G2'
        obj = new G2();
 
        // call 'gfg1()' of class 'G2'
        obj.gfg1();
    }
}
 
 

Output :

Class name is G1 Class name is  G2

Like a class, Interface can have methods, properties, events, and indexers as its members. But interfaces will contain only the declaration of the members. The implementation of interface’s members will be given by the class who implements the interface implicitly or explicitly. Example: 

CSharp




// C# program to illustrate the
// concept of interface
using System;
 
// A simple interface
interface interface1 {
 
    // method having only declaration
    // not definition
    void show();
}
 
// A class that implements the interface.
class MyClass : interface1 {
 
    // providing the body part of function
    public void show()
    {
        Console.WriteLine("Welcome to GeeksforGeeks!!!");
    }
 
    // Main Method
    public static void Main(String[] args)
    {
 
        // Creating object
        MyClass obj1 = new MyClass();
 
        // calling method
        obj1.show();
    }
}
 
 

Output:

Welcome to GeeksforGeeks!!!

Difference between Abstract Class and Interface

Abstract Class Interface
It contains both declaration and implementation parts. It contains only the declaration of methods, properties, events, or indexers. Since C# 8, default implementations can also be included in interfaces.
Multiple inheritance is not achieved by abstract class. Multiple inheritance is achieved by interface.
It contain constructor. It does not contain constructor.
It can contain static members. It does not contain static members.
It can contain different types of access modifiers like public, private, protected etc. It only contains public access modifier because everything in the interface is public.
The performance of an abstract class is fast. The performance of interface is slow because it requires time to search actual method in the corresponding class.
It is used to implement the core identity of class. It is used to implement peripheral abilities of class.
A class can only use one abstract class. A class can use multiple interface.
If many implementations are of the same kind and use common behavior, then it is superior to use abstract class. If many implementations only share methods, then it is superior to use Interface.
Abstract class can contain methods, fields, constants, etc. Interface can only contains methods, properties, indexers, events.
The keyword “:” can be used for implementing the Abstract class. The keyword “:” and “,” can be used for implementing the Interface.
It can be fully, partially or not implemented. It should be fully implemented.
To declare abstract class , we use abstract keyword. To declare interface, we use interface keyword.

Example of Abstract class:-

public abstract class Fruits{
public abstract void Mango();

}

Example of Interface:-

public interface Readable{
void read();
}



Next Article
Difference Between List and Set in C#
author
ankita_saini
Improve
Article Tags :
  • C#
  • CSharp-Interfaces
  • CSharp-OOP

Similar Reads

  • Difference between Class and Structure in C#
    In C#, both classes and structures are used to define custom data types, but there are some differences between them. Inheritance: A class can inherit from other classes, but a structure cannot. In other words, a class can be derived from another class, but a structure cannot be. Reference type vs V
    5 min read
  • Difference Between List and Set in C#
    The list is C# is the same as the list in JAVA. Basically, it is a type of object which can store variables. But in difference with objects, it stores the variables only in a specific order. Following is the syntax from which we can declare variables: Syntax: List<int> numbers = new List<in
    2 min read
  • Difference Between Properties and Indexers in C#
    Properties in C# are named members that use access modifiers to set and retrieve values of fields declared in a secured manner. Properties are used for abstracting and encapsulating access to a field of a class by defining only important actions and hiding their implementation. Properties are invoke
    2 min read
  • Difference between var and dynamic in C#
    Implicitly Typed Local Variables – var are those variables which are declared without specifying the .NET type explicitly. In implicitly typed variable, the type of the variable is automatically deduced at compile time by the compiler from the value used to initialize the variable. The implicitly ty
    4 min read
  • Difference Between VB.NET and C#
    Visual Basic .NET is a high-level programming language that was initially developed in 1991. It was the first programming language that directly supported programming graphical user interfaces using language-supplied objects. It supports all the concepts of an object-oriented such as object, class,
    2 min read
  • Difference between Boxing and Unboxing in C#
    Boxing and unboxing is an important concept in C#. C# Type System contains three data types: Value Types (int, char, etc), Reference Types (object) and Pointer Types. Basically, it converts a Value Type to a Reference Type, and vice versa. Boxing and Unboxing enables a unified view of the type syste
    2 min read
  • Difference Between C# and ASP.NET
    Pre-requisites: C#, ASP.NET C# (also known as C sharp) is an object-oriented programming language that is used to produce an array of applications for gaming, mobile, web, and Windows platforms also It is a modern and type-safe language and provides simple syntax which makes it easier to learn and i
    2 min read
  • Difference between Managed and Unmanaged code in .NET
    Managed code is the code which is managed by the CLR(Common Language Runtime) in .NET Framework. Whereas the Unmanaged code is the code which is directly executed by the operating system. Below are some important differences between the Managed code and Unmanaged code: Managed Code Unmanaged Code It
    2 min read
  • C# Program to Inherit an Abstract Class and Interface in the Same Class
    Abstract Class is the way to achieve abstraction. It is a special class that never be instantiated directly. This class should contain at least one abstract method in it and mark by abstract keyword in the class definition. The main purpose of this class is to give a blueprint for derived classes an
    3 min read
  • Difference between Method Overriding and Method Hiding in C#
    Method Overriding is a technique that allows the invoking of functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called Method Overriding. In simple words, Overriding is a feature that allows
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences