In the same class:
For static methods, other static or non-static methods can be called directly.
For non-static methods, other non-static methods can be called directly. But other static methods can only call it through objects.
Static methods cannot be overwritten by non-static methods.
public class Test2 { public static void s1(){ System.out.println("s1"); } public void says1(){ System.out.println("say1"); } public void says(){ s1(); say1(); //Call the say1 method} public static void main(String [] args ) { s1(); Test2 t = new Test2(); t.say(); } }jpg
Between different classes, regardless of whether the calling method is non-static or static, if the called method is:
Static methods can be tuned through both class names and objects (but they are not recommended to use them through objects because they belong to non-static calls)
Non-static method can only be called through an object
public class CallTest2 { public static void s(){ System.out.println("s1"); } public void says(){ Test2 t2 = new Test2();//Calling the method t2.say(); t2.s1(); Test2.s1(); } public static void main(String [] args ) { CallTest2 t = new CallTest2(); t.say(); } }The above Java implementation of calling another method in one method is the entire content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.