Method inner Classes in Java

Source: Internet
Author: User

The inner class of the method is the inner class defined in the method of the outer class, and the inner class of the method can only be visible inside the method, that is, it can only be used inside the method

Features of the inner class of the method:

1. The object that creates the inner class of the method is the same as the static inner class ;

2. The inner class of the method cannot be used outside the method, so access control and static modifiers cannot be used;

  

1  Packagecom.imooc.test003;2 3  Public classOuter {4 5      Public voidTest () {6         7         intA = 10;8         9         //method inner class; access control and static modifiers cannot be usedTen         classminner{ One              A             intb = 20; -              -              Public voidprint () { the                  -SYSTEM.OUT.PRINTLN ("Accessing constants in external class methods A:" +a); -SYSTEM.OUT.PRINTLN ("Variable B in the Access method inner class:" +b); -                  +             } -              +         } A          atMinner mi =NewMinner (); - mi.print (); -          -     } -      -      Public Static voidMain (string[] args) { inOuter in =NewOuter ();//to create an object of an inner class - in.test (); to     } +      -}
View Code

Reference: MU-Class network (http://www.imooc.com/)

Method inner Classes 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.