CJCoding With Joseph
15free / daySign inCreate account

Product declares its stock field as protected, so code inside a subclass can read and change it directly, while unrelated classes cannot. Perishable extends Product. Complete discard.

Requirements: 1. discard(int count) lowers stock by count. 2. stock never goes below 0. If more items are discarded than are left, stock becomes 0. 3. Use the inherited stock field itself. Do not declare a new field in Perishable.

The Product class is provided. Do not change it.

Do NOT write a main method.

Expected output

Milk: 7
Milk: 3

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
InheritanceClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.