We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have a class super and two sub classes. objects of one of these sub classes are getting added to an ArrayList<super> and at one point I'm calling a run() method for all objects in the arraylist, which is a method each sub class has its own version of. that call is throwing the "function doesn't exist". So is this structure not allowed or is it something else in the code?
Answers
Your post is in "Questions about Code" category. But you haven't provided any code! X_X
Nonetheless,
super
is a Java's reserved keyword and thus can't be used as label of anything! [-Xhttps://processing.org/reference/super.html
Have you tried adding a dummy version of your function to the super class?
@TFGuy44: thank you so much, specially for the effort of putting the example together! do you happen to know why it's necessary to have that dummy in the superclass? I'd never encountered that issue before, but then again I can't be sure I've put myself in a situation like this before..
@GoToLoop: I should have just left it in "programming questions"? also, I didn't mean that my actual class was called super, I was just using those terms to explain the situation =P
super
, Parent, Base or even Super would be less prone to be mis-interpreted!I don't know why it works. I've run into this issue before too myself. It's not really great for learning inheritance. Ideally you wouldn't have to specify it in the base/super class...
As said, showing some code reproducing the behavior your describe would help us in diagnosing your issue. You don't have to give all your code, on the contrary. Try and make a couple of dummy classes showing how you do, so we can try on our own and advise.
TFGuy44's suggestion fixed it, like I said, but thanks.
If your code is similar to TFGuy44's one, then it is clearer: if Super class hasn't the name() function, the problem is that the code gets instances of Super, which can be Sub or Submarine actually. But Super doesn't has a name() method (from what I understand of your problem). If you have never instances of Super, you can make it an abstract class: then you can declare an abstract name() function: no need to give it code, but the code will know all subclasses will have the method.