0% found this document useful (0 votes)
20 views1 page

Abstract Classes Versus Interfaces

Abstract classes and interfaces both act as base types in C#, but there are key differences between them. Abstract classes can include access modifiers and implementations of members, while interfaces cannot have access modifiers or implementations. A class can inherit from multiple interfaces but only one abstract class or interface, and an interface can only inherit from another interface while an abstract class can inherit from an abstract class or interface.

Uploaded by

Akash Negi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Abstract Classes Versus Interfaces

Abstract classes and interfaces both act as base types in C#, but there are key differences between them. Abstract classes can include access modifiers and implementations of members, while interfaces cannot have access modifiers or implementations. A class can inherit from multiple interfaces but only one abstract class or interface, and an interface can only inherit from another interface while an abstract class can inherit from an abstract class or interface.

Uploaded by

Akash Negi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Abstract Classes versus Interfaces

While both of them acts as base types, there are quite significant differences
between abstract classes and interfaces in C#. Few noteworthy points are as follows

Abstract classes can have access modifiers whereas interfaces doesnt have
access modifiers
Abstract class can inherit either from another abstract class or another
interface while an interface can inherit only from an interface.
A class can inherit more than one interface, while a class cannot inherit
multiple classes at the same time.
While interfaces cant have implementation of any members, abstract classes
can have.

Illustration code
using System;
public abstract class JIMS
{
int RollNo;
public void print() //abstract class can have implemetations
{
Console.WriteLine("This is a print method");
}
}
public interface iJIMS
{
/* public void print() // interfaces can not have implementations nor access specifier and it
will give an error.
{
Console.WriteLine("This is a print method");
}*/
//int RollNo; // interfaces can not have fields while abstract classes can have
void Print();
}
public class Program
{
public static void Main()
{
Console.WriteLine("46geekslab - Difference between abstract classes and Interfaces in
c#");
Console.ReadLine();
}
}

You might also like