Number in java how it work without a subclass?

Viewed 371

I want to know why the result of this code:

Number x = 3;
System.out.println(x.intValue());
System.out.println(x.doubleValue());

generates

3
3.0

as Number is an abstract class in Java.

So when I need to use it - I could use it with some it's subclasses like Integer, Double ...etc. Now I want to know how exactly this part of code works:

Number x = 3;
7 Answers
Related