Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Two methods have key words static synchronized and synchronized separately. What is the difference between them?
Two methods have key words static synchronized and synchronized separately. What is the difference between them?
✍: Guest
Both are synchronized methods. One is instance method, the other is class method. Method with static modifier is a class method. That means the method belongs to class itself and can be accessed directly with class name and is also called Singleton design. The method without static modifier is an instance method. That means the instance method belongs to its object. Every instance of the class gets its own copy of its instance method.
When synchronized is used with a static method, a lock for the entire class is obtained. When synchronized is used with a non-static method, a lock for the particular object (that means instance) of the class is obtained.
Since both methods are synchronized methods, you are not asked to explain what is a synchronized method. You are asked to tell the difference between instance and class method. Of course, your explanation to how synchronized keyword works doesn't hurt. And you may use this opportunity to show your knowledge scope.
2012-08-30, 2240👍, 0💬
Popular Posts:
How To Build WHERE Criteria with Web Form Search Fields? - MySQL FAQs - Managing Tables and Running ...
.NET INTERVIEW QUESTIONS - What is Suspend and Resume in Threading ? It is Similar to Sleep and Inte...
How was XML handled during COM times? During COM it was done by using MSXML 4.0. So old languages li...
Managed Code and Unmanaged Code related ASP.NET - How do you hide Public .NET Classes and other publ...
What Is URI? URI (Uniform Resource Identifier) is a superset of URL. URI provides a simple and exten...