From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create overloaded methods

Create overloaded methods - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Create overloaded methods

- [Instructor] A Java class can implement more than one method of the same name. But each of the methods must have a different signature. A method signature is determined by the method's name, and then the number and types of its parameters. In this starting application, I have two methods. The getInput method, which receives a Scanner object and a String and returns an integer value. And a method that I've added named addValues, it receives two integer values and adds them together and returns the result. I'll run the application and show that I can enter a value, and enter another one and get back the sum. Now, I want to add a new version of the addValues method. I'll select these lines of code and duplicate them. And I'll change this version so it receives four integer variables. I'll name the third one i3 and the fourth one i4. Then, I'll change the return statement to add all those values together. Notice that…

Contents