Javase Review Diary: interface

Source: Internet
Author: User

/* * interface * Reference data type: * Class, interface, array; * * Interface is a reference data type that can be As a special class, its existence is designed to solve the problem of weak functionality caused by multiple inheritance, a class can have only one parent class, but this class can implement multiple interfaces; * * Interfaces can also be considered as classes with only abstract methods, that is, all methods of an interface must be implemented; * The keyword of the interface declaration is interface, instead of class, and the inheritance keyword extends of the common class becomes the implements (implementation); * But its function is the same as the ordinary class, but only to distinguish; * * * 1 defines the syntax of the interface: * [modifier list] Interface interface Name {} * 2 interface content: * Can only be constant (public static final constant name) and abstract party       Method * 3 Abstract methods do not need to be modified, the default is public (do not need to add) * 4 interface can be regarded as a special abstract class, is completely abstract, there is no ordinary method * 5 interface is no construction method, that is, the interface can not be instantiated * 61 classes can implement multiple interfaces, but only one class * 71 non-abstract class implementation interface, you need to implement all the methods in the interface (override/overwrite) * That abstract class implementation interface? * Abstract class implementation interface, can implement any: 0~n * 8 interface between: * can inherit, not only that, the interface can also inherit more, compared to the class can only inherit * * Constant and static data difference: * All is initialized at the time the class is loaded, but static data can be assigned multiple times * constants: Generally, the public static final decoration must be used to declare constants in the interface, which can be omitted; * Naming mode: uppercase and lowercase with an underscore in the form of name; * Note: The above section needs to distinguish between interface and interface "Inheritance", Class and interface "Implementation", Class and Class "inheritance"; */ Public classjavase{ Public Static voidMain (string[] args) {f f=NewF ();        F.M1 ();        F.M2 ();        F.M3 ();    F.M4 (); }}Interfacea{//interface A     Public voidM1 ();}Interfaceb{//Interface B     Public voidm2 ();}Interfacec{//Interface C    voidM3 ();//The public of the method in the interface can be omitted;}InterfaceD extends a,b,c{//multiple inheritance of interfaces    voidM4 ();}classMyClass Implements b,c{//implementation of common class-to-interface     Public voidm2 () {System. out. println ("m2 () method for overwrite B interface" ); }     Public voidm3 () {System. out. println ("m3 () method for overwrite C interface" ); }}Abstract classE Implements d{//implementation of an abstract class-to-interface     Public StaticFinalintA =Ten;//how constants are declared    CharE'in';  Public voidM1 () {} Public voidm2 () {} Public voidm3 () {} Public voidM4 () {}}classF extends e{//need to overwrite all the methods in E     Public voidM1 () {System. out. println ("Overwrite M1 () method" ); }     Public voidm2 () {System. out. println ("overwrite m2 () method" ); }     Public voidm3 () {System. out. println ("overwrite m3 () method" ); }     Public voidM4 () {System. out. println ("overwrite the M4 () method in D" ); }}

Javase Review Diary: 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.