I’m trying to establish a default value for inherited fields from superclasses.
So, my class hierarchy is thus:
Character -> Enemy -> Boss
\
-> Hero
Each Character has a public static char avatar to represent him on an ASCII playing field.
How do I set a default value for the avatar of each class inherited from Character?
Thank you!
You could set it in the constructor. For example:
But, for this to work, avatar property must not be static (othervise all your avatars will be the same, as set in the constructor of the last instantiated class). Your Character class should probably look something like this (provided that you want default avatar for classes that don’t set theirs in constructor):