Can you write virtual functions / methods in Java?

yonatan picture yonatan · Dec 28, 2010 · Viewed 219.1k times · Source

Is it possible to write virtual methods in Java, as one would do in C++?

Or, is there a proper Java approach which you can implement that produces similar behavior? Could I please have some examples?

Answer

Klaus Byskov Pedersen picture Klaus Byskov Pedersen · Dec 28, 2010

From wikipedia

In Java, all non-static methods are by default "virtual functions." Only methods marked with the keyword final, which cannot be overridden, along with private methods, which are not inherited, are non-virtual.