Home > Tutorial for Beginners > Use of Non Abstract Method of Abstract Class in C#

Use of Non Abstract Method of Abstract Class in C#

You can have non abstract method in abstract class; as such I didn’t find any use of these methods. Yes this is an option. May be it is useful in some situations when you want to call those methods inside your abstract methods.

As per abstraction rules, you cannot create the object of abstract class, means you cannot use the "new" keyword.

You can create any class as an abstract class with the help of “Abstract” keyword; even you can create any method as an abstract method inside the class. Abstract class can have both type of method “Abstract” & “Non Abstract”. You can inherit these classes inside the non abstract classes.
Abstract classes cannot have the implementations details of abstract methods.

How to declare Abstract class with Abstract & Non Abstract methods
public abstract class Class1
{
   //non abstract class
   public void GetDetails()
   {
       // implementation details
   }

   //Abstract method.
   public abstract int Total();

}

How to use Abstract Class
public class myNormalclass : Class1
{
   public void myNormalclass()
   {

   }

   public override int Total()
   {
       // code implementation details…
       //of abstract methods
       throw new NotImplementedException();
   }
}

If you notice in my above code I am using "override" keyword to override the abstract method of my class.  Then I can create the object of myNormalclass class.

Post Comments Below

  1. No comments yet.
  1. No trackbacks yet.