Does Java support virtual functions?
6558 Since 25th November, 2003
Select and Copy the Code
No, Java does not support virtual functions directly as supported by C++. Virtual functions can be implemented in Java using abstract classes and interfaces. Abstract class is a class with declaration of methods, but without their implementation. The implementation of the methods takes place in the subclasses. Another example of virtual functions is interfaces. The only difference between an abstract class and an interface is that abstract classes can be used only when they are superclasses and the subclass implements their methods. Whereas in an interface the methods can be implemented even by classes, which are not inherited.