Local inner class of the member inner class of the Java inner class

Source: Internet
Author: User

Local inner class features:
1. A class defined in a code block or method body is called a local inner class
2. The local inner class accesses the properties and methods of the external class using the "external class name." This. The name of the property and the external class name. This is the form of the method name (parameter)
3. Completely hidden from the outside world, the object can only be generated within the scope.
Local inner classes have the following limitations:
1. Local classes cannot add access modifiers because they are not class members
2. The member inner class cannot duplicate the name of the external class
3. Local internal class accesses local variables within the scope, the local variable needs to be final decorated

public class Localinnerclass {public static void main (string[] args) {//TODO auto-generated method StubOuter3 Outer3 = NE W Outer3 (); Outer3. Outershow ();}} class Outer3{private int num1 = 1;private static int num2 = 2;public void Outershow () {final int num4 = 4;//FIANL seems to have been repaired, not declared For final in the inner class can also be used (can be removed final)//inner Inner = new Inner (), cannot be instantiated here, because the Inner class has not been initialized, you cannot call that class inner{// Local inner class cannot add access modifier public void show () {int num1 = 10; System.out.println (NUM1); System.out.println (OUTER3.THIS.NUM1);//Call the properties of the external class System.out.println (outer3.num2);// Call external static property notation System.out.println (NUM4);}} Inner Inner = new Inner ();//should be instantiated here Inner.show ();}}

  

Local inner class of the member inner class of the Java inner class

Related Article

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.