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 is visible only within the method, that is, it can be used only inside the method.

Be aware of this : because the method inner class cannot be used outside the methods of the outer class, the method inner class cannot use the access control and the static modifier

Task

Pro, let's do a practice test.

The HelloWorld class is defined in the editor, there is a show method in the class, and a method inner class Minner is defined in the Show method, please complete the code in section 17, 20, and line.

Program Run Result:

//External Class Public classHelloWorld {PrivateString name = "Adoration Class"; //Show methods in external classes     Public voidShow () {//defining method Inner classes        classMinner {intScore = 83;  Public intGetscore () {returnScore + 10; }        }                //to create an object of a method inner classMinner mo =NewMinner (); //methods for calling inner classes        intNewscore=Mo.getscore (); System.out.println ("Name:" + name + "\ n Bonus Score:" +NewsCore); }        //test method Inner class     Public Static voidMain (string[] args) {//create an object of an external classHelloWorld mo =NewHelloWorld (); //methods for calling external classesmo.show (); }}

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.