Java object-oriented internal classes and interfaces

Source: Internet
Author: User

An internal class

1 member Inner class

???????????? Class 1.1, outside called outer outer class, inside called inner inner class

????????????? 1.2 Inner class usually attendant outside class, externally with invisible

???????????? 1.3 objects are typically created in an external class

???????????? 1.4 Direct access to all members of the outer class, an implicit reference to the outer class object that created it, and the external name of the

2 Anonymous inner class:

  1. ??? To create an object of a class and create it only once, the class does not have to be named, which is called an anonymous inner class.
  2. In an anonymous inner class, if you want to access an external variable, the variable must be final------------jdk1.7 and before

Two interfaces:

      1. is a data type (reference type)
      2. There is a interface definition
      3. can only contain constants and abstract methods
      4. Interface cannot be instantiated
      5. Interfaces are required to be implemented or inherited, implementations or inheriting classes must override all methods in an interface
      6. A class can implement multiple interfaces, separated, and if inherited and implemented, must first inherit after implementation
      7. Interfaces can inherit interfaces

Three design rules:

1 properties and behaviors common to all derived classes pumped into the superclass---pumping commonalities

2 All derived classes behave the same as normal methods, all derived classes behave differently, and are set to abstract methods

3 to extract the behavior shared by some derived classes into the connector

An interface is an extension of the inheritance of a single root = = Multiple inheritance

Use interfaces when both inherit and implement

Java object-oriented internal classes and interfaces

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.