0
What is runtime polymorphism in Java?
Can someone explain what runtime polymorphism is in Java? How does it work when a subclass overrides a method? How does the JVM decide which method to call at runtime?
3 Antworten
0
It only works if there is created an object of the subclass where the overrided method exist.
0
if subclass SubC is downcasted:
C c = new SubC();
c.method();
• is C.method() overrided ?
yes - use SubC.method()
no - use C.method()
0
I have read a blog about runtime polymorphism in Java, which explains that it allows a method to behave differently based on the object it is invoked on, determined at runtime. This is accomplished through method overriding in Java. If you're interested in learning more, I suggest you read this blog: https://uncodemy.com/blog/virtual-function-in-java-run-time-polymorphism-in-java/