Computer Science, asked by jahnavipande6874, 11 months ago

Enumerate two situations in which static methods are used

Answers

Answered by riteshoberoi
0

Explanation:

Coursera, etc

Monday, July 10, 2017

When to Make a Method Static in Java

Making a method static in Java is an important decision . Though, static keyword is one of the fundamental concepts, many times programmers gets confused to make a particular method static or not. In Java programming, main motivation for making a method static is convenience. You can call a static method without creating any object, just by using it's class name. So if you need a method, which you want to call directly by class name, make that method static. Utility classes e.g. java.lang.Math or StringUtils, are good examples of classes, which uses static methods. Before making a method static, you should look into limitation of static methods as well, as you can not override static method in Java.

By keeping these properties in mind, we can make few rules, which will help to decide when to make a method static in Java and when to use them.

  1. In this Java article, we will learn more about benefits and limitation of making a method static, and also see couple of examples of static methods from JDK to learn when and how to use static method in Java.
Similar questions