Question

Could anyone please explain me this? or can you write this other way? Thank you public...

Could anyone please explain me this? or can you write this other way? Thank you

public double getTotal() {

return (item1==null?0:item1.getPrice())+

(item2==null?0:item2.getPrice())+

(item3==null?0:item3.getPrice());

0 0
Add a comment Improve this question Transcribed image text
Answer #1

It's a recursive function their are three different ternary operator statement . In , First statement if the value of item is equal to null then value return is zero otherwise it call get price function . These all three statement execute in same way. These all statement execute in using diff. Diff. Stack. And the end of function they all return value. Which is add and return by function.

Add a comment
Know the answer?
Add Answer to:
Could anyone please explain me this? or can you write this other way? Thank you public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT