Search code examples
scalamethodsjvmoverridingvirtual

Is member function virtual by default


Is member function virtual by default in scala? Is it different than Java in this matter?

When a method is overriden you have to explicitly state that, but there is no "virtual".


Solution

  • Is member function virtual by default in scala?

    Yes.

    Is it different than Java in this matter?

    No, in Java methods are also virtual unless they're explicitly defined as final.

    However Java is different from Scala in that Java doesn't require (or have) the override keyword in order to override methods - it does have an @override annotation though (since Java 1.5) and gives a warning when you override a method without that annotation.