Scala – Method Overloading

In previous post, we have seen what is auxiliary constructor . Now, let’s understand the method overloading in scala.

What is method overloading?

When a class can have multiple methods with same name but different no. of parameters or different data type, will be called as method overloading. We will understand that with an example.

Method overloading with different parameters:

As you can see below , Addition class have 2 methods named add different parameters. We have created an object name obj and called both of the methods.

Method overloading with different datatypes:

In the below example, we have multiple methods with same name and same no. of parameters but different data types.

Scala - Auxiliary Constructor
Scala - Method Overriding
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

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