Abstract class in C#:-

0
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();
       }
   }

}


    
Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)