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