This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IS-A relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IS-A relationship" Watch "IS-A relationship" New topic
Author

IS-A relationship

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi, This is part from K&B mock exam question.

In some cases, is-a relationships are used in the process of autoboxing.: TRUE..How ?? Please provide an example.
Given Explanation : For instance, you can autobox an int to a Number (via an Integer).
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Saibabaa Pragada wrote:
Given Explanation : For instance, you can autobox an int to a Number (via an Integer).


Like this?....

Number n = 24;



Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
I tried this using IS-A relation but I am getting compile error. Don't know where I am going wrong
Henry Wong wrote:
Saibabaa Pragada wrote:
Given Explanation : For instance, you can autobox an int to a Number (via an Integer).


Like this?....

Number n = 24;


Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

actually this is related to overriding
in the subclass
you are writing the method which override the superclass methods
and overriding method rules say that

the return type should be same or the subclass of the return type
This is not about boxing and unboxing

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi Prasad, I think you are referring about covariant return types. I am looking for this "In some cases, is-a relationships are used in the process of autoboxing.: TRUE..How ?? Please provide an example, that would be really helpful. "
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

Then your query is simple
this is a sample program that can make you understand the concept
here we are returning an int value that is getting autoboxed into Integer
and Integer IS-A Number
so return type Number is also valid

this is called as Boxing and then Widening


hope this helps now
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Great..Thanks Prasad !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IS-A relationship