Scala Field OverridingIn scala, you can override fields also but it has some rules that need to be followed. Below are some examples that illustrate how to override fields. Scala Field Overriding Example1Output: Error - variable speed needs 'override' modifier In scala, you must use either override keyword or override annotation when you are overriding methods or fields of super class. If you don't do this, compiler reports an error and stops execution of program. Scala Field Overriding Example2Output: 100 In scala, you can override only those variables which are declared by using val keyword in both classes. Below are some interesting examples which demonstrate the whole process. Scala Field Overriding Example3Output: variable speed cannot override a mutable variable Scala Field Overriding Example4Output: Error - variable speed needs to be a stable, immutable value Next TopicScala Final |