• Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiate an abstract class?  RSS feed

 
matt love
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Number is an abstract class, why does the following print the affirmative?

Is the int being boxed to an Integer?



Thanks.

Matt

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does n.getClass() tell you?
 
matt love
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class java.lang.Integer


Thanks Bear.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
matt love wrote:If Number is an abstract class, why does the following print the affirmative?


Because an object IS-AN instance of every one of its superclasses and of every interface that it implements and that its superclasses implement.

Is the int being boxed to an Integer?


Yup. If it weren't being boxed to something, you'd get a compile-time error on the n = assignment. And what else would it be boxed to if not an Integer?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!