• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCPJP Coding Exercises: Question 3c (Numeric Wrapper Classes)

 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,


Sharing my solution to the coding exercises for objective 3 from the book 'Practice Exams' by Bert Bates and Kathy Sierra.
This solution seems fine to me, do correct me if I am wrong or if there would be a better way of coding it.
Hope like minded souls would find this post useful. Thank you.



RESULT:
43


regards
John
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see only two numeric wrappers in your code. Where is the third one?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heena Agarwal wrote:I can see only two numeric wrappers in your code. Where is the third one?


The third wrapper class is created in the compute(Byte, Integer) method on line 22 after the evaluation of the expression completes in the statement -> Integer y = j+k;
The arguments j and k will be unboxed, their values added and the result will be boxed into an Integer object and assigned to the reference variable y.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the question expects the third wrapper to be a different wrapper.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or may be not. It just says a third wrapper instance.

Anyway, I know those steps. But thanks.

One small correction - It's not the third wrapper 'class' that gets created. It's an instance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic