Hello all,
Here's the breakdown. I have a Beverage superclass, with a few properly extended subclasses (tea,
coffee, tequila and beer). Now, I have this Menu class, which creates an ArrayList called menu of element type <Beverage>.
I have been trying to add the different beverages to the menu ArrayList via menu.add() method, but this has not worked. I constructed all of the Beverage objects first, and then attempted to append them to the menu.
While I have had no trouble adding objects of different generic and reference types to an ArrayList before, I haven't had the same success with this program. Is there something about inheritance that I should know?
I am just starting to practice with inheritance. Please let me know what you all think is going on here.
I'll include a snippet of code below. Trust that I have no apparent syntax errors with the Beverage superclass and its extended classes:
And here is the outputted error suggestions for line 10:
Multiple markers at this line
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error on token ".", @ expected after this token
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "SimpleName" to complete QualifiedName
tl;dr:
I can't seem to add (what I thought are) subclasses of an element type to an ArrayList of that type.
Cheers,
T