3

If base class A has a "public synchronized void method(){}" which was not overridden by its derived class B,then what will the lock be (i.e. will it be the derived class object or the base class object) that is used to access the synchronized method in class B?

2
  • This is not a static method, is it? Commented Nov 7, 2013 at 18:34
  • No.Not even block synchronized like synchronized(A.class) or synchronized(getClass()) or synchronized(Class.forName("A")) Commented Nov 7, 2013 at 18:42

2 Answers 2

4

There is no "base class object".

synchronized methods lock on the instance they're called on.

Sign up to request clarification or add additional context in comments.

Comments

0
public synchronized void method() { ... }; 

is just the same as

public void method() { synchronized(this){ ... } }; 

And for a super-method this means an object of class B. So the lock will be on an instance of the object B.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.