Yes, we can declare an overloaded method as static and another one as non-static.
Example
class SubtractionTest { public void subtraction(int num1, int num2) { System.out.println(num1 - num2); } public static void subtraction(int num1, int num2, int num3) { System.out.println(num1 - num2 - num3); } } public class Main { public static void main(String[] args) { SubtractionTest subtractionTest = new SubtractionTest(); subtractionTest.subtraction(150, 100); SubtractionTest.subtraction(150, 100, 20); } } |
Example
50 30 |
Java interview questions on method overloading and overriding
- What is method overloading in java?
- Can we declare an overloaded method as static and another one as non-static?
- Can overloaded methods be synchronized?
- Synchronized override method
- Can we declare overloaded methods as final?
- Can overloaded method be overridden?
- What is method overriding in java?
- Can static method be overridden?
- Difference between method overloading and overriding in java?
- Can we override private methods in java?
- Is it possible to override non static method as static method?