File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Master Exam / Autoboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Master Exam / Autoboxing" Watch "Master Exam / Autoboxing" New topic
Author

Master Exam / Autoboxing

John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 165
In question 52 of Master Exam 2 the following statement is considered to be true: 'In some cases, is-a relationships are used in the process of autoboxing'.

Does anybody has an example? When an int is boxed to an Integer then this is not an is-a relationship I think (we cannot say 'int is-an Integer' as int is not an object')?

Thanks,

John
s patnaik
Ranch Hand

Joined: Jul 17, 2011
Posts: 41

For example,

Number number = 10;

Here 10 which is an int is boxed to Integer. As, Integer "is a" Number, int 10 gets boxed and then widened to a Number. Or in other words, int 10 gets autoboxed to Number.

Hope that helps.


SCJP 5, OCPJP7, OCMJEA 5
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1061
is-a relationship and autoboxing is another thread about this subject....

Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 165
Number number = 10;

Doh, haven't thought about it. You can even do


Thanks for the answers,

John
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 2687

The key thing to remember (and you may already have this), is that you can box-then-widen:

Number n = 10;

But you cannot widen-then-box:

Long ln = 10;
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 165
The key thing to remember (and you may already have this), is that you can box-then-widen:

Number n = 10;

But you cannot widen-then-box:

Long ln = 10;


Yes, had taken me a while to understand this. Should be clear now

John
 
 
subject: Master Exam / Autoboxing
 
Threads others viewed
Mock test question from Inquisition John Meyer's test
Why said undetermined output?
casting int to Integer
is-a relationship and autoboxing.
Wrapper Question
developer file tools