
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Can I Overload Static Methods in Java
Overloading is a one of the mechanisms to achieve polymorphism where, a class contains two methods with same name and different parameters.
Whenever you call this method the method body will be bound with the method call based on the parameters.
Example
public class Calculator { public int addition(int a , int b){ int result = a+b; return result; } public int addition(int a , int b, int c){ int result = a+b+c; return result; } public static void main(String args[]){ Calculator cal = new Calculator(); System.out.println(cal.addition(12, 13, 15)); } }
Output
40
Overloading static methods
Yes, we can overload static methods in Java.
Example
public class Calculator { public static int addition(int a , int b){ int result = a+b; return result; } public static int addition(int a , int b, int c){ int result = a+b+c; return result; } public static void main(String args[]){ System.out.println(Calculator.addition(12, 13)); System.out.println(Calculator.addition(12, 13, 15)); } }
Output
25 40
Advertisements