

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
abstract keyword in C#
The abstract keyword in C# is used for abstract classes. An abstract class in C# includes abstract and nonabstract methods. You cannot instantiate an abstract class.
Example of an abstract class Vehicle and abstract method display() −
public abstract class Vehicle { public abstract void display(); }
The abstract class has derived classes: Bus, Car, and Motorcycle. The following is an implementation of the Car derived class −
public class Car : Vehicle { public override void display() { Console.WriteLine("Car"); } }
Example
The following is an example of abstract classes in C# −
using System; public abstract class Vehicle { public abstract void display(); } public class Bus : Vehicle { public override void display() { Console.WriteLine("Bus"); } } public class Car : Vehicle { public override void display() { Console.WriteLine("Car"); } } public class Motorcycle : Vehicle { public override void display() { Console.WriteLine("Motorcycle"); } } public class MyClass { public static void Main() { Vehicle v; v = new Bus(); v.display(); v = new Car(); v.display(); v = new Motorcycle(); v.display(); } }
Output
Bus Car Motorcycle
- Related Questions & Answers
- The abstract keyword in Java
- 'abstract' keyword in Java
- Abstract class in Java
- Abstract Classes in Java
- Abstract Classes in C#
- Can we define an abstract class without abstract method in java?
- Can we define an abstract class with no abstract methods in Java?
- Explain abstract class in PHP.
- Abstract Classes in Dart Programming
- what are abstract methods in Java?
- What are abstract classes in Java?
- Abstract Method and Classes in Java
- What are abstract classes in C#?
- What are abstract properties in C#?
- Abstract Base Classes in Python (abc)
Advertisements