
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Method overloading in Java
Method overloading is a type of static polymorphism. In Method overloading, we can define multiple methods with the same name but with different parameters. Consider the following example program.
Example
public class Tester { public static void main(String args[]) { Tester tester = new Tester(); System.out.println(tester.add(1, 2)); System.out.println(tester.add(1, 2,3)); } public int add(int a, int b) { return a + b; } public int add(int a, int b, int c) { return a + b + c; } }
Output
3 6
Here we’ve used a method add() which can take either two or three parameters and can acts accordingly. This is called method overloading or static polymorphism.
- Related Articles
- Using Method Overloading in Java
- What is method overloading in Java?
- Difference between Method Overloading and Method Overriding in Java
- method overloading and type promotion in Java
- Method Overloading and null error in Java
- Method Overloading and Ambiguity in Varargs in Java
- Method overloading with autoboxing and widening in Java.
- What is the difference between method overloading and method hiding in Java?
- What are the restrictions placed on method overloading in java?
- Method Overloading based on the order of the arguments in Java
- Constructor overloading in Java
- Overloading in java programming
- Java Program to Find Area of circle Using Method Overloading
- Java Program to Find Area of Rectangle Using Method Overloading
- Java Program to Find Area of Square Using Method Overloading

Advertisements