I have two classes:
public class ClassA {
public void method(Number n) {
System.out.println(\"ClassA: \" + n + \" \" + n.getClass());
}
}
a is of type ClassA so the methods in ClassB will not be visible to instance a unless it is declared as ClassB
ClassB a = new ClassB();
will produce your expected output. Number is the supertype of Integer. So whatever you pass in will be autoboxed to appropriate subtype and the method in ClassA will be called. Try passing
a.method(3.0f) // Float
a.method(3.0) // Double