0
When there are several extends (as in the example below) all methods are overwritten to the last extends? If not, which method will be used?
class D extends C {
  void x() {
    System.out.println(1);
  }
}
class C extends B {
  void x() {
    System.out.println(2);
  }
}
class B {
  void x() {
    System.out.println(3);
  }
  void y(B b) {
    b.x();
  }
  void y(C c) {
    c.x();
  }
  void y(D d) {
    d.x();
  }
}
class A {
  public static void main(String[] args) {
    new B().y(new C());
  }
}
Vlw friend, it was very clear, I wrote wrong was really methods. To be sure if I understood, if by chance I wrote "new B(). x()" instead of "new B(). y(new C())" would perform the polymorphism and return "1"?
– Robson Novaes
This code has no polymorphism anywhere, much less in this part, but would result in 1 in a simple and direct way.
– Maniero
has no superscript?
– Robson Novaes
There is no polymorphism.
– Maniero
Blz vlw for all, helped me a lot, I need to try to understand better the term polymorphism.
– Robson Novaes
That’s why I put a link in the answer.
– Maniero