How to call static methods in java
This article is a detailed introduction to "how to call static methods in java". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to call static methods in java" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.
1. First, we need to create a new.java file in the java development tool eclipse, and then write a static method inside the file. The code is as follows:
package User_DY;public class DY_Test {public static String ody="static attribute";public static void ODY_Function(){ System.out.println("We called static methods");}
In the code, we use static to modify a static property and methods that generate a static class.
2. So through the previous step, after we get the method, now let's see if we make a call, then the following is our code and screenshot:
package User_DY;public class DY_Test {public static String ody="static attribute";public static void ODY_Function(){ System.out.println("We called static methods");}public static void main(String[] agrs){ DY_Test dt=new DY_Test(); dt.ODY_Function(); }}
In the code block, we add a new class object to the new code, and then call our static method through the class object, and output a result we want in the console, then we can actually use another method to call, that is, directly call the method through the class.
Read here, this article "how to call static methods in java" article has been introduced, want to master the knowledge points of this article also need to be used by ourselves to understand, if you want to know more related content articles, welcome to pay attention to industry information channel.