Reputation: 1052
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?
Upvotes: 3
Views: 766
Reputation: 16476
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
.
Upvotes: 0
Reputation: 887225
There is no "base class object".
synchronized
methods lock on the instance they're called on.
Upvotes: 4