Yes, overloaded methods can be synchronized in java.
Note: But you will get mutual exclusive problem if all methods are synchronized and you are using same object to invoke them. So, instead of using synchronized keyword at method level, try to follow below approach.
class LoggerTest { private final Object LOCK = new Object(); public void logTest(String s) { synchronized (LOCK) { //logger statements } } public void logTest(int i) { synchronized (LOCK) { //logger statements } } } |
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?