* 5th member of class: inner class
* 1. The equivalent of saying that we can redefine the class within the class. Outside class: The outer class. The class defined inside: Inner class
* 2. Classification of inner classes: member inner Class (declared inside the class and outside the method) vs local Inner class (declared in the method of the Class)
* 3. member Inner class:
* 3.1 is a member of an external class: ① can have modifiers (4) ②static Final③ can invoke properties, methods of external classes
*
* 3.2 Specific class features: ①abstract② can also define properties, methods, constructors in its internal
*
* 4. Local inner class:
*
* 5. For the inner class, we have three points:
*① How to create an object of a member's inner class (for example, to create an object of the bird class and the dog Class)
*② How to distinguish variables that call external classes, inner classes (especially when the names of variables are identical)
*③ use of local inner classes (see Testinnerclass1.java)
*
1 Public classTestinnerclass {2 Public Static voidMain (string[] args) {3 //create objects of static inner classes: constructors for static inner classes can be called directly from an external class4Person.dog d =NewPerson.dog ();//person.new Dog ();5 //Person.bird B = new Person.bird ();6 //create an object of a non-static inner class: You must first create an object of the outer class, call the constructor of the inner class through an object of the outer class7Person p =NewPerson ();8Person.bird B = P.NewBird ();//new P.bird ();9 b.info ();TenB.setname ("Cuckoo"); One } A } - - classperson{ theString name = "Han Meimei"; - intAge ; - //member Inner class (non-static) - classbird{ +String name = "Oriole"; - intID; + A PublicBird () { at - } - Public voidsetName (String name) { -SYSTEM.OUT.PRINTLN (name);//Cuckoo -System.out.println ( This. name);//Oriole -System.out.println (person. This. name);//Han Meimei in } - Public voidinfo () { to Show (); + } - } the //member inner Class (Static inner Class) * Static classdog{ $ Panax Notoginseng } - the Public voidShow () { +System.out.println ("I am Show () method"); A } the + Public voidmethod1 () { - classa{ $ $ } - } -}
Java Learning--internal classes