From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Overloading methods with different signatures - Java Tutorial
From the course: Java 8 Essential Training
Overloading methods with different signatures
- Java supports the concept of method overloading. That means that you can create more than one version of a method. You just have to distinguish them from each other by the number of arguments or the arguments' data types, so that the Java run time knows which method to call. In this project, I've declared two methods named getInput and addValues. They both receive arguments. The getInput method receives a string named prompt. And it displays that prompt, then creates a scanner object, and uses the scanner object to return a value. The addValues method receives two string arguments. It parses those values, adds them together, and then returns the result. Notice that both methods have data types set as the return types. GetInput returns a string, and addValues returns a double. And they're both marked as static so that they can be called from my static main method. Now, I'm going to create two more versions of the addValues method. I'll copy and paste the original version. Notice when…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Programming conditional logic3m 45s
-
(Locked)
Using the switch statement4m 51s
-
(Locked)
Creating looping code blocks5m 23s
-
(Locked)
Creating reusable code with methods4m 15s
-
(Locked)
Overloading methods with different signatures4m 51s
-
(Locked)
Passing arguments by reference or by value4m 47s
-
(Locked)
Challenge: Creating a more complex calculator application1m 53s
-
(Locked)
Solution: Creating a more complex calculator application3m 23s
-
(Locked)
-
-
-
-
-
-