Can I find out if a class is an abstract class before trying to instantiate it?

Illustration
Sam - 2023-11-03T09:46:16+00:00
Question: Can I find out if a class is an abstract class before trying to instantiate it?

Can i somehow say:   if isAbstract(className)   % do something else % do something else end

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

A class is abstract if any of its properties or methods is abstract.
 
It's possible to write a function, is_abstract. Start:
 
    mco = ?my_class
    mco.PropertyList
    mco.MethodList

    any([mco.MethodList.Abstract])
or better
    mcls = meta.class.fromName('ClassName')

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!