Can anyone help ?
1)where we need to use static methods & static variable in a real time projects?
2)How to Count total numbers of object created by that class in java by using static variable's ?
Static variables are shared among objects of the same class.
If you have a class called MyClass with a static variable called myVariable, then there's only ever one copy of myVariable no matter how many objects you create of type MyClass. So all MyClass type objects share the same myVariable.
To count how many instances of a class are created, you need to have a static variable in that class and increment its value everytime a new object is created from that class. A possible place to put the code for the incrementing is in an
instance initializer block.