JAVA Program Dynamic method dispatch
![]() |
JAVA |
JAVA Program to implement Dynamic method dispatch.
Program / Code:
class Radio{
void callme()
{
System.out.println("callme method
of Class Radio");
}
}
class Television extends Radio{
void callme()
{
System.out.println("callme method
of Class Television");
}
}
class Smartphone extends Radio{
void callme()
{
System.out.println("callme method
of Class Smartphone");
}
}
class
DMD{
public static void main(String args[]){
Radio obj1=new Radio();
Television obj2=new Television();
Smartphone obj3=new Smartphone();
Radio ref=new Radio();
ref=obj1;
ref.callme();
ref=obj2;
ref.callme();
ref=obj3;
ref.callme();
}
}
No comments:
Your comment will be visible after review.