Java essay three

Source: Internet
Author: User

1. Interface:

1) The interface is not a class and cannot instantiate an interface with the new operator, but rather a set of requirements descriptions for classes that are defined in a uniform format that follows the interface description. Personal feeling like a function in C is pre-declared in a header file, but contains some of the characteristics of a class, such as inheritance.

2) All methods in the interface are automatically public and do not have to provide keywords, but must provide pulic when implementing the interface.

3) Let the class implement an interface: (1) Declare the class to implement the given interface (implements) (2) to define all the methods in the interface;

4) An object that cannot construct an interface, but can declare a variable of an interface, and the variable of the interface must refer to the object that implements the interface's class.

5) The interface can contain constants, and the fields in the interface are automatically set to public static final.

6) interfaces can be multiple-inherited compared to abstract classes.

2. Inner class:

1) The Inner class method can access the data in the scope where the class definition resides, including private;

2) Inner classes can be hidden from other classes in the same package;

3) When you want to define a callback function and do not want to write a large number of code, the use of anonymous internal classes is convenient;

4) An object of an inner class always has an implicit reference to the outer class object that created it (which is not visible in the inner class definition), whereas the perimeter class is outerclass.this, and the inner part can be referenced outerclass.innerclass outside the scope of the perimeter class.

5) Local inner class: An inner class that is defined in a method (cannot use modifiers, scoped to a block that declares a local class), can be completely hidden from the outside, and only the methods in the declaration block can be accessed.

6) Anonymous inner class: In a local inner class, if you only create an object of this class, you do not have to name it, and because there is no class name, the anonymous class cannot have a constructor, but instead passes the constructor arguments to the superclass constructor. (If the enclosing parenthesis of the construction parameter is followed by a flower brace, the anonymous inner class is being defined.)

7) If you do not need an inner class to reference a perimeter class object, you can declare the internal as static so that the resulting reference is canceled. (Only inner classes can be declared as static)

Java essay three

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.