1 //static and non-static call issues. 2 Public classStaticdemo3 {4 /*5 It is shown here that a static method (here is the Main method) cannot call a non-static method directly, and you can invoke the object by creating that class .6 public void info ()7 {8 System.out.println ("Simple info Method! ");9 }Ten Public static void Main (string[] args) One { A Staticdemo s = new Staticdemo (); - s.info (); - } the */ - Public Static voidinfo () - { -SYSTEM.OUT.PRINTLN ("Simple info Method! "); + } - Public Static voidMain (string[] args) + { AStaticdemo s =NewStaticdemo (); atS.info ();//This is also true for invoking static members with an object, which is not recommended because the static - //members should be called with the class name. - - //new Staticdemo (). info ();//and the above two sentences are the same effect. It's just called using an anonymous object. - - //info (); //This invocation is true because the class name call is used by default and is equivalent to the following call. in - //Staticdemo.info (); //This is the underlying invocation principle, when calling static, if the object is not used to invoke the to //, and the class name is omitted, the following paragraph is called by default with the class name: + //("Crazy java Handout" If you call the static decorated member (including the method, - //member variable) omits the previous keynote, the class is used by default as the keynote. ) the } *}
"Static and non-static call problems"