"Static and non-static call problems"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.