I have the following program but it wont compile:
public class A {
public void method() {
System.out.println ("bla");
}
}
class AX extends A {
public void method(int a) {
System.out.println ("Blabla");
}
public static void main(String[] args) {
A a2 = new AX();
a2.method(5);
}
}
Why doesn't a2.method(5) use the subclasses method? Isn't this method overloading?
a2.method(5)will definitely call the subclass's method, since there is no method with a matching signature inA.AX.a2has only the visibility of methods from classA.