Here in method overriding, we observed that method overriding is a disadvantageous fact, because in this concept only sub class property is coming as output, super class property is hidden. So to eliminate this disadvantage we need run-time polymorphism which is also known as dynamic method dispatch.
wap to illustrate dynamic method dispatch
DynamicMethodDispatchDemo.java
package java8s;
class Example { void print() { System.out.println("javacamp.in"); } } class Example12 extends Example { void print() { System.out.println("java8s.com"); } } class Example123 extends Example { void print() { System.out.println("javabytrilochan.blogspot.in"); } } public class DynamicMethodDispatchDemo { public static void main(String[] args) { Example ref; Example ob1=new Example(); Example12 ob2=new Example12(); Example123 ob3=new Example123(); ref=ob1; ref.print(); ref=ob2; ref.print(); ref=ob3; ref.print(); } }
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc