Java Learning--internal classes

Source: Internet
Author: User

* 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

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.