C# Abstraction

Last modified: July 11, 2021

Abstraction is the process of hiding certain detail and it can be used for class and method. Abstract class does not allow to the creation of an object it and the abstract method can only use in abstract class.

abstract class Vehicle { // Abstract method (does not have a body) public abstract void myTopSpeed(); public void brack() { Console.WriteLine("Vehicle brack"); } } // Derived class (inherit from Vehicle) class Car : Vehicle { public override void myTopSpeed() { Console.WriteLine("My top speed: 408.47 km/h"); } } class Program { static void Main(string[] args) { Car myCar = new Car(); // Create a Car object myCar.myTopSpeed(); // Call the abstract method myCar.brack(); // Call the regular method } }