• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IS-A relationship

 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saibabaa Pragada wrote:
Given Explanation : For instance, you can autobox an int to a Number (via an Integer).


Like this?....

Number n = 24;


 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great..Thanks Prasad !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic