This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes OCPJP Coding Exercises: Question 3c (Numeric Wrapper Classes) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "OCPJP Coding Exercises: Question 3c (Numeric Wrapper Classes)" Watch "OCPJP Coding Exercises: Question 3c (Numeric Wrapper Classes)" New topic
Author

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

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 121
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

Joined: Dec 25, 2013
Posts: 261
    
    4
I can see only two numeric wrappers in your code. Where is the third one?
Rico Felix
Ranch Hand

Joined: Mar 08, 2014
Posts: 227
    
    3

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

Joined: Dec 25, 2013
Posts: 261
    
    4
I think the question expects the third wrapper to be a different wrapper.
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
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.
 
 
subject: OCPJP Coding Exercises: Question 3c (Numeric Wrapper Classes)
 
Similar Threads
Wrapper Classes Autoboxing Concept
Wrapper - Swap
Integer problem
Where to find ans for mock test by Valentinn Cretazz
Autoboxing doubt