Javatpoint Logo
Javatpoint Logo

Scala Method Overriding

When a subclass has the same name method as defined in the parent class, it is known as method overriding. When subclass wants to provide a specific implementation for the method defined in the parent class, it overrides method from parent class.

In scala, you must use either override keyword or override annotation to override methods from parent class.


Scala Method Overriding Example 1

Output:

Bike is running

Real example of method overriding

Flowchart

Scala Inheritance 3

Scala Method Overriding Example 2

This example shows how subclasses override the method of parent class.

Output:

SBI Rate of Interest: 8
ICICI Rate of Interest: 7
AXIS Rate of Interest: 9




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA