An Abstract class is an incomplete class or special class we can't instantiate. We can use an Abstract class as a Base Class. An Abstract method must be implemented in the non-Abstract class using the override keyword. After overriding the abstract method is in the non-Abstract class. We can derive this class in another class and again we can override the same abstract method with it. Features:
Example 1:
#region
//An abstract calss can inherit from a class and one or more interfaces. interface IVendorTransDetails { void getVendorID(); } interface IClaimsTracker { void getSeqID(); } class ClaimsMaster { string getDCNNO() { return "PC20100308A00005"; } }Example 2:abstract class Abstract : ClaimsMaster, IClaimsTracker, IVendorTransDetails{ //Here we should implement modifiers oterwise it throws complie-time error public void getVendorID() { int s = new int(); s = 001; Console.Write(s); }
public void getSeqID() { int SeqID = new int(); SeqID = 001; Console.Write(SeqID); }} #endregionExample 3:
//An abstract class can implement code with non-Abstract methods.
abstract class NonAbstractMethod{ //It is a Non-abstract method we should implement code into the non-abstract method on the class. public string getDcn() { return "PS20100301A0012"; } public abstract void getSeqID(); } class Utilize : NonAbstractMethod{ public override void getSeqID() { }
} #endregionExample 4: #region //Abstract class can have modifiers for methods,properties and An abstract class can implement a propertypublic abstract class abstractModifier{ private int id; public int ID { get { return id; } set { id = value; } } internal abstract void Add();} #endregionExample 5: #region //Abstract class can have constant and fields public abstract class ConstantFields { public int no; private const int id = 10; } #endregionExample 6: #region //An abstract class can have constructors or destructors abstract class ConsDes { ConsDes() { } ~ConsDes() { } } #endregionExample 7: #region //An abstract class cannot be inherited from by structures public struct test { } //We can't inheritance the struct class on the abstract class abstract class NotInheritanceStruct { } #endregionExample 8: #region //An abstract class cannot support multiple inheritance class A { } class B : A { } abstract class Container : B //But we can't iherit like this : A,B { } #endregionConclusion : In this article I have given some simple examples to understand abstract classes. I am expecting feedback about this article.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: