@Acer since Tomato() is only a special case of Tomato(int size), you may try

Tomato(){ this(_default_size); }

not sure, I’m no java expert XD

@Acer And I don't think it's a good idea to call setFoodName in the constructor. Say you want to change the food name from "Tomato" to "StrangeRedApple", you have to rewrite every single function attribute.

I would simply set the member foodName to "Tomato", and every time you need the name, you do "this.foodName" or "getFoodName()"..
Follow

@shrik3

it will throw error if writing foodName directly.
I dont know the exact reason. maybe it is because foodname is private variable of Food instead of Tomato

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.