| 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: 16680
|
|
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
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 !!
|
 |
 |
|
|
subject: IS-A relationship
|
|
|