You can't put a function call on the left-hand side of an assignment. That just doesn't make sense.
If medication
weren't private
, you could just have your method assign to it. Since it's private
, you can't. There are two solutions:
Change
private
toprotected
in thePatient
class. This lets child classes access it directly, while outside clients still can't see themedication
field.(my preferred method) Add a
setMedication
method to the parent (Patient
). You could make thisprotected
so that child classes could callsetMedication
while outside clients could not. In any event, theInPatient
class would use that method to setmedication
(using the syntaxsuper.setMedication(medication)
so that it calls the method in the parent class).