Which of the following is a valid synchronized method declaration?
- public synchronized void myMethod() {}
- public void myMethod() { synchronized() {} }
- public void synchronized myMethod() {}
- synchronized void myMethod() {}
The correct syntax for a synchronized method declaration in Java is public synchronized void myMethod() {}, where the synchronized keyword comes before the access modifier (public) and the return type (void). This ensures that only one thread can execute the myMethod at a time.
Loading...
Related Quiz
- Deadlock occurs when two or more threads are blocked forever, each waiting for the other to ________.
- BufferedReader uses a default buffer size of ________ characters unless specified otherwise.
- In which version of Java were Lambda expressions introduced?
- Which of the following classes are byte stream classes in Java?
- In which scenario would you choose an abstract class over an interface?