What is Abstraction?

Shikhar Arora

Total Post:6

Points:42

Posted by  Shikhar Arora
C#
 724  View(s)
Ratings:
Rate this:
What is Abstraction C#?
  1. Re: What is Abstraction?

    Abstraction is showing the working of the machine but not the internal parts of the machine or the complexity of the machine. An abstract class cannot be instantiated. Only abstract methods can be declared in an abstract class which is necessary for the class, without them the class is of no use.

     namespace ConsoleApplication5 
     {
         abstract class Car //abstract class
         {
             public abstract void Start();
             public abstract void Stop();
         }
         class Program:Car
         {
        //Overriding abstract methods
             public override void Start()
             {
                 Console.WriteLine("Car has started");
             }
             public override void Stop()
             {
                 Console.WriteLine("Car has stopped");
             }
             public void ApplyBrakes()
             {
                 Console.WriteLine("Brakes have been applied");
             }
             static void Main(string[] args)
             {
                 Program obj = new Program();//Instantiating Program class
                 //Calling abstract methods
                 obj.Start();
                 obj.ApplyBrakes();
                 obj.Stop();
                 Console.ReadLine();
             }
         }
     }

      Modified On Nov-12-2019 02:10:01 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.