Junior — Middle
How to determine the base class from which inheritance occurs in object-oriented programming?
sobes.tech AI
Answer from AI
In C#, the base class from which inheritance occurs is specified after a colon in the class declaration. For example:
class DerivedClass : BaseClass
{
// class body
}
Here, BaseClass is the base class, and DerivedClass is the derived class. If no base class is specified, the class inherits from object by default.
You can also determine the base class using reflection:
Type type = typeof(DerivedClass);
Type baseType = type.BaseType;
Console.WriteLine(baseType.Name); // Outputs the name of the base class