Scala Final

In Scala, Final is a keyword that is used to prevent inheritance of super class in any of the child classes.We can declare variables, methods and classes with Final keyword. Let’s understand them with example one by one.

Scala Final variable:

In the below example, we have declared a final variable named as ‘age’. So, it can not be inherited in the child class ”employee”.It throws error message as ‘Variable age can not override final member’.

Scala Final Method:

In the below example, the method named ‘display’ is a final method in parent class. So, this method can not be overridden in child class.

Scala Final Class:

In the below example, Parent class is created as final class. It can not be extended by any other class.

Scala Field Overriding
Scala Functions
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *