Results 1 to 2 of 2
- 09-13-2011, 12:09 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
What is the need of dynamic method dispatch?
What is the need of the above code if we can call the method using the objects a, b and c?Java Code:A a = new A(); // object of type A B b = new B(); // object of type B C c = new C(); // object of type C A r; // obtain a reference of type A r = a; // r refers to an A object r.callme(); // calls A's version of callme r = b; // r refers to a B object r.callme(); // calls B's version of callme r = c; // r refers to a C object r.callme(); // calls C's version of callme
- 09-13-2011, 02:41 PM #2
Re: What is the need of dynamic method dispatch?
I am not too sure what the point of that is. I would assume that callme() is a function within the object 'a','b', and 'c'. There really is no need to have a reference to any of the functions in this particular example because all you have to do is
I assume this practice is to show you how you can use one object to reference another but I personally have never needed to use this.Java Code:a.callme(); b.callme(); c.callme();
I could see this being useful if you need to obtain a certain method that a program cannot get its hands on and must use an method reference in order to get it. I cannot think of an example where you would need this though.My API:Java Code:cat > a.out || cat > main.class
Similar Threads
-
please explain me dynamic methos dispatch
By ajjukumar in forum New To JavaReplies: 3Last Post: 12-15-2010, 07:11 PM -
please explain me dynamic methos dispatch
By ajjukumar in forum New To JavaReplies: 3Last Post: 12-10-2010, 09:37 AM -
Dynamic Method Dispatch
By sandeshforu in forum New To JavaReplies: 0Last Post: 09-15-2009, 05:18 PM -
Dynamic method calling
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks