Difference Between Interface and Abstract Class in Java & C#

JavaCsharpServer Side ProgrammingProgramming

In this post, we will understand the difference between abstract class and interface in Java and C#.

Abstract Class

  • It contains the declaration and definition part.

  • Multiple inheritance can’t be implemented using abstract class.

  • It contains the constructor.

  • It can also contain some static members.

  • It can contain multiple types of access modifiers such as public, private, protected.

  • The performance of an abstract class is very good, because it is quick.

  • It is used to implement the core identity/functionality of a class.

  • A class can use only one abstract class.

  • If many implementations are same, and they have a common behaviour, it is suggested to use an abstract class.

  • Abstract classes contain methods, fields, constants.

  • It can be fully implemented, partially implemented or not even implemented.

Interface

  • It contains a declaration part only.

  • Multiple inheritance can be achieved using interface.

  • It doesn’t contain a constructor.

  • It doesn’t contain static members.

  • It contains public access modifier since everything in an interface is considered public.

  • The performance of interface is not good.

  • It is slow since it needs time to search for an actual method in the respective class.

  • It is used to implement peripheral abilities of a class.

  • It can use multiple interface.

  • If multiple implementations share methods, then the ‘Interface’ can be used.

  • Interface can contain methods only.

  • It needs to be fully implemented.

raja
Published on 24-Mar-2021 13:11:13
Advertisements