Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the child class name from base class?

At run-time, inside base class, how to find the current child class name ?

like image 544
Xaqron Avatar asked Jan 23 '11 16:01

Xaqron


People also ask

How do you access an inherited class from base class?

To access an element of a base class from an inherited class, you need to use the base keyword. The base keyword is used in inherited classes in the following cases: when from the constructor of a derived class you need to call the constructor of the base class.

How do you find the class name for a subclass?

The Class object has a getName() method that returns the name of the class. So your displayClass() method can call getClass(), and then getName() on the Class object, to get the name of the class of the object it finds itself in.

How do I get child class in Python?

When a class has a parent class in Python, we can get the child class name from the parent class. Product, not Product instance, has the __subclasses__ method that returns a list of child classes. So t has Book class information and t. __name__ is Book, Product's child class name.


1 Answers

Get the type of the current object, then its name.

this.GetType().Name 
like image 180
tvanfosson Avatar answered Sep 25 '22 23:09

tvanfosson