Hi, On Jan 31, 2:06 pm, suren <[email protected]> wrote: > What is the use of static method? Is this to give access only to > static members or any other reason behind this? Even it is not a > static method it ll be shared by all objects of particular class. Why > we really need a static method?
This is a difficult question, when you start to use a language, when the reason for a language design is asked for. Static methods do not need an instance. e.g the Math Class has a lot of static methods. The processing in this methods do not need an instance. Everything can be done in this one method with Math.<methodname> (<arguments>), otherwise you have to create an instance when you invoke such a method. The main-Method is a static method. At the start you do not have an instance. The factory design pattern/singletons use static methods. ( they often do not have public constructors to prevent creating a direct instance). HTH Ewald -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
