Originally posted by Vijaylaxmi Agarwal:
Hi all,
Please tell me the difference between static and private static method and where are they used.
Thanks in advance
Hello and welcome to JavaRanch.
Static modifier is used to create variables and methods that will exist independently of any instance created for the class. Static members exists before any instance of the class is created.
Also there will be only one copy of the static member.
To call a static method displayRuns() of the class named Cricket we write
Cricket.displayRuns();
Class name is used to invoke the static method as static member does not depend on any instance of the class.
private static method means you can not invoke the method from outside the class as the method is private to the class.
Hope you get the explanation.