July 2017
Intermediate to advanced
796 pages
18h 55m
English
Just like Java, the final keyword also exists in Scala, which works somehow similar to the val keyword. In order to differentiate between the val and final keywords in Scala, let's declare a simple animal class, as follows:
class Animal { val age = 2 }
As mentioned in Chapter 1, Introduction to Scala, while listing Scala features, Scala can override variables which don't exist in Java:
class Cat extends Animal{ override val age = 3 def printAge ={ println(age) }}
Now, before going deeper, a quick discussion on the keyword extends is a mandate. Refer to the following information box for details.
Read now
Unlock full access