Question 1

(b) Explain the followings:
(i) Dynamic Method Dispatch with example
class First
{
void display()
{
System.out.println("First Class's metohd Display");
}
}
class Second extends First
{
void display()
{
System.out.println("Second Class's metohd Display");
}
}
class Third extends First
{
void display()
{
System.out.println("Third Class's metohd Display");
}
}
public class dynamicMethodDispatchExampleH2E
{
public static void main(String args[])
{
First f = new First();
Second s = new Second();
Third t = new Third();
First fRef;
fRef = f;
fRef.display();
fRef = s;
fRef.display();
fRef = t;
fRef.display();

}
}

Make Comments..!!


Nikul Virani
thx.......h2e
Like · Comment ·
Download Android App