Java Java Objects Harnessing the Power of Objects Filling the Dispenser

Please help

Why did we write "pezCount = 0;" in PezDispenser constructor? and why we created another VOID constructo with no retur?

1 Answer

alastair cooper
alastair cooper
25,420 Points

The constructor is the method that creates the object. When you make a Pez dispenser, you would make an empty one and then fill it with sweets. So on creation, the number of Pez in the dispenser is 0.

A constructor cannot be declared void, as it can't return anything but the object it creates

hope this helps