Here subclass is hiding the static method of superclass, so lock is being taken on two different class instance one on LowTop.class and other is HighTop.class. So result is unpredictable.
But if subclass does not hide static method than what will happen?
Doubt: Still lock would be taken on two different instances or lock of HighTop.class instance would be shared by two threads. Here result is predictable or not? [ December 16, 2008: Message edited by: Punit Singh ]
Synchronized static methods lock the class, not the instance ;-)
Joined: Oct 16, 2008
I know Jean, synchronized static method locks on class that is: YourClass.class, means on the class instance, and synchronized instance method locks on object, means on the object instance of the class.
A class has two types of instance, one is Object instance that is new YourClass(), and other is class instance that is YourClass.class that returns java.lang.Class instance of your class.
jean-gobert de coster
Joined: Dec 04, 2008
Well since your LowTop class doesn't technically inherit the method, it's the staticMethod() of HiTop that will be called by both run() mehods, hence locking the HiTop class.