You call a user-defined function the same way you call a built-in function; by calling its name followed by the input in (). Let’s call the sum function we defined above. We will store the return value of the function in a variable result.
While println is a method, it is a very simple one which only requires passing it an argument which can be of any type. However, most methods require you to call them on something, let’s call that something an object for now. That object can be anything from AnyVal to AnyRef. For example, objectName.method(argument) means that the method is being called on objectName and argument are parameters passed to the method. The method will perform some action on the data stored in objectName.
Most methods allow you to only pass an argument of a specific data type. Let’s call one of Scalas built-in methods, indexOf to get a better idea of how this works.
IndexOf is called on a string and you pass it one argument of type Char. It is used to calculate the index of a character in a string.