Java Programming thought Note Nineth Chapter interface

Source: Internet
Author: User

1. Abstract classes and abstract methods

1.1 Abstract methods, only method declarations have no method body

Abstract class abstractclass{    abstractvoid// No {}    }

1.2 To have one or more abstract methods, it must be an abstract class, and abstract classes can have no abstract methods.

1.3 Abstract classes can have no abstract methods, or can only implement methods.

Abstract class abstractclass{        void  g () {        System.out.println ("Hello");}    }

1.4 Inherit the abstract class, to overwrite all abstract methods within the abstract class, to provide the method body, if you do not provide a method body then this subclass is also an abstract class, the preceding will be added keyword

2. Interface

There is no specific implementation within the 2.1 interface, and there is no method body.

Method default public permissions in the 2.2 interface

2.3 Interfaces can have domains, but are implicitly set to static and final

2.4 Interface permissions are public as well as classes, but must be in a file of the same name

3. Covariant Type:
    • The overridden method in a subclass returns a type that can be a subtype of the return value of a parent class method
classA {}classBextendsA {}Abstract classAbstractClass {AbstractA g ();}classCextendsAbstractClass {//The return value type is type a//A g () {//return null; // }    //g () The return value type is a subtype of type B can also overwriteB g () {return NULL; }}
4. Multiple inheritance

4.1 Interface extends interface, interface, interface, ...

4.2 Class extends interface, interface, interface, ...

Class 4.3 extends class implements interface, interface, interface, ...

4.4 Class implements interface, interface, interface, ...

    • Implement multiple interfaces in which you should avoid having the same method name
5. Nested interfaces
    • Interfaces can be nested within a class or in other sockets

5.1 The nested interfaces/classes are treated outside Class A as data members of Class A, as normal interfaces/classes within Class A

Class or interface permissions that are nested in class 5.2 can be private

5.3 An interface in an interface cannot be declared as private because the method in the interface is default public

5.4 The private interface in a nested function is to make the method in this private interface has no return type and cannot be transformed upward

class A {    public class  ain{                         }    // internal class permission can be set to private    Privateclass  ain2{                  }    publicinterface aface{            }    privateinterface  aface2{        void // must return a null value     }    }
6. Interface and Factory
    • Pending additions

Java Programming thought Note Nineth Chapter interface

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.