File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is meant by a 'virtual method'?

 
Mallesham Karnati
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I know about static and non-static methods in java. But, what is a 'virtual method' and why is it called so?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In C++ and C#, a virtual method is one that is polymorphic. In Java, all non-static method are virtual, all static methods aren't.
 
Mallesham Karnati
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja for your quick response. Could you please tell me why non-static methods are called 'virtual'? I am not able to figure out the significance of the term 'virtual' in this context.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't use the virtual keyword directly. C++ and C# do. The Java compiler itself has a virtual mode by which it resolves references at runtime rather than at compile time. Is that what you're referring to?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In many OO languages, polymorphism is implemented by the use of so-called "virtual jump tables". Basically, when a polymorphic method is called, the address of the code to execute is looked up in a table associated with the object. That's why polymorphic methods are also often called "virtual" in those languages.

Does that help?
 
Mallesham Karnati
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja for your answer. Now I understad it clearly.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic