Suppose this code
class A
{
public synchronized void methodA()
{
// ...
}
}
class B extends A
{
@Override
public synchronized void methodA()
{
// ...
super.methodA();
}
}
What lock should be acquired by any thread if it wants to access methodA function of class B and methodA of super class A by super.methodA()
?
When you call B b = new B(); b.methodA();
current thread will aquire lock on b
, enter B.methodA
and call A.methodA
. Both methods share the same object and when entering A.methodA
the thread will just re-enter the same lock which it already owns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With