
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Using Method Overloading in Java
- What is method overloading in Java?
- Method overloading v/s 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 is the difference between method overloading and method overriding in Java?
- Constructor overloading in Java
- Overloading in java programming
- What are the restrictions placed on method overloading in java?
- What is method overloading in C#?
- What is method overloading in PHP?
- Constructor Overloading In Java programming
Advertisements