Answer the question
In order to leave comments, you need to log in
Does polymorphism work when calling methods inside a superclass?
The question is something like this, is there a superclass
public class SuperClass {
//...
public void method0(){ /*Назовем этот блок кода А*/}
public void method1(){ this.method0() };
//...
}
public class SubClass extends SuperClass {
//...
@Override
public void method0(){ /*А этот Б*/}
//...
}
SuperClass ob = new SubClass();
ob.method1();
Answer the question
In order to leave comments, you need to log in
It would be faster to test it yourself by putting the output to the console in the method0 () method in the superclass and in the subclass.
Must call block B because it is a virtual method and the code version is determined by the real class of the object. Unless java has a special syntax with the this keyword.
Check it out for yourself, it will take a couple of minutes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question