The source code to check a specified class is an abstract class or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to check a specified class
//is an abstract class or not.
using System;
using System.Reflection;
abstract class Student
{
public abstract void Method();
}
class Program
{
static void Main()
{
Type type = typeof(Student);
if (type.IsAbstract == true)
{
Console.WriteLine("Student class is an abstract class");
}
else
{
Console.WriteLine("Student class is not an abstract class");
}
}
}
Output:
Student class is an abstract class
Press any key to continue . . .
Explanation:
In the above program, we created two classes Student and Program. Here, Student class is an abstract class. The Program class is a non-abstract class that contains the Main() method. The Main() method is the entry point for the program. Here, we check the Student class is an abstract class or not using the IsAbstract property of Type class and printed the appropriate message on the console screen.
Program:
The source code to check a specified class is an abstract class or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created two classes Student and Program. Here, Student class is an abstract class. The Program class is a non-abstract class that contains the Main() method. The Main() method is the entry point for the program. Here, we check the Student class is an abstract class or not using the IsAbstract property of Type class and printed the appropriate message on the console screen.