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 ]
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.
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.
the output will thus always be
A0 A1 A2 A3 A4 A0 A1 A2 A3 A4
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad: