how to have a only number type in java

Solutions on MaxInterview for how to have a only number type in java by the best coders in the world

showing results for - "how to have a only number type in java"
Isidora
25 May 2018
1class scratch{
2    public static Number haha(Number yo){
3        return yo;
4    }
5
6    public static void main(String[] args) {
7        System.out.println(haha( (int) 5 ));
8        System.out.println(haha( (double) 5.0 ));
9        System.out.println(haha( (long) 5 ));
10        System.out.println(haha( (float) 5.0 ));
11        //all of these classes extend the java.lang.Number class 
12
13        System.out.println(haha("Hey"));
14        //error because the java.lang.String class does not extend the java.lang.Number class
15    }
16}