Member variables, local variables, local inner classes, local inner class method scope problems in Java.

Source: Internet
Author: User

 public classA {String s = "outer class member variable";//member Variables         public voidMethod () {//member Methods        FinalString S1 = "inner class variable";//Local Variables        classInnerclass {//local inner class             public voidInnermethod () {//local Inner class method                intTest = 20;                System.out.println (s); System.out.println ("Integer value is:" +test);            System.out.println (s1); }} Innerclass b=NewInnerclass ();        can only be instantiated in a local inner class.               B.innermethod ();    And only methods in the class can be called, and external methods cannot be called. }     public Static voidmain (string[] Args) {a a=NewA ();    A.method (); }}

One the inner class defined in the method body (local inner Class) innerclass can only access local variables that are declared final as defined in the Method. Member variables are not final Decorated.

second, The local inner class can only be instantiated in the class, and can only invoke methods inside that class. is not instantiated and invoked in an external class.

third, the Operation Result:

Member variables, local variables, local inner classes, local inner class method scope problems in Java.

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.