Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Abstract class in C#:-  


It is a special class of C# which contains a normal method and abstract method, we can not create objects of abstract class it will be implemented by the normal class.

An abstract class is used to declare a set of rules using the abstract method but we can not perform multiple inheritances using this.



Syntax:-

abstract class Classname
{
       void methodname()
      {

       }

      abstract void methodname();

}

note:-  all abstract methods must be overridden, we will use abstract keywords in class and method both.


We can not create an object of abstract class hence it is also used to perform data abstraction.

abstract class  Area
    {
       internal void rect()
       {
       }
      abstract internal  void triangle();
     
    }

 class AreaLogic: Area
    {

        internal override void triangle()
        {
            Console.WriteLine("Triangle");
        }
     
        static void Main()
        {
            Area obj = new AreaLogic();
            obj.rect();
            obj.triangle();
         
            Console.ReadKey();
        }
    }


Another Example of Abstract Class using Head Branch and SuBranch:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project2
{
   abstract class AbstractBank
    {
       internal void Details()
       {
           Console.WriteLine("Bank name is SBI");
       }
      abstract internal void Transaction();
    }

   class SubBranch : AbstractBank
   {
       internal override void Transaction()
       {
           Console.WriteLine("Sub Branch Transaction");
       }

       static void Main()
       {
           SubBranch obj = new SubBranch();
           obj.Details();
           obj.Transaction();
           Console.ReadKey();
       }
   }

}


    

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post