What’s the purpose of Static methods and static variables in Java?

3 votes
371 views
Anonymous User asked 19-Dec-2017 in Technology by Anonymous User

What’s the purpose of Static methods and static variables in Java?

1 Answer

2 votes
Anonymous User answered 20-Dec-2017 by Anonymous User
The method and variables marked as static when it belongs to a class rather than to any particular instance of the class. During development of the project when there is a need to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects. In Java, only the class is adequate to invoke a static method or access a static variable.Where a static variable is shared by all the instances of that class, means only one copy of the static variable is maintained.