The question might be confusing and i don’t know how to explain it better, but an example should show what i mean.
Lets say we have some objects with different classes <Banana, Apple, Bread, and so on>.
And now i want to get their respective classes supercathegory like <Fruit, WheatProduct, and so on>.
Usually i would just make the class be Fruit and have Banana extend it (or implement it, not too much experience using that). But if i can’t do that, how would i go about saving their respective target class. So lets say we have Banana already extend (or so). And lets say we could not just change extension order, like Plant>Fruit>Banana, but have to have Plant>Banana, and then we need to access Fruit, from within Banana.
That could be done by just writing (Fruit) before the variable that would need this, or inside the ( element brackets, don’t know what they are called exactly, but those that define the class used ie. for a container), but the first is not modular once executed, and the second is not what i’m looking for. Now, i want the Banana object know that it should know that it is a Fruit, and that it can access some of Fruits methods and variables. How would i do that?
I mean, one option is to have each class have an ObjectArray with all classes that the Banana or Bread could be in, and then just get them via index (or strings for hashMaps) but that would require every class to have a whole array of objects in it. The other method would be to add a switch statement with and just set to Fruit if the String input is “Fruit”, but thats also a bit ugh… And just having the whole code switch once for each cathegory, is way too inefficient.
So, this could have proably been abbreviated by just saying that i’m looking for a way to store a Class in a Variable. (And so that it is not an Object and not a (elemental thingy))
Sorry for the confusing example