[Thiinking in Java] autistic way of learning (c) interface

Foreword -

This article is to learn to sort out the nature of the personal notes do, certainly with a lot wrong with it, for information purposes only.

(Chapter IX · Interface "Thinking in Java")

  interface keywords make abstract concepts like before a step forward.

 

text-

  Abstract classes and interfaces -

  abstract keyword allows people to create in the class do not have any one or more of the methods defined - provides part of the interface, but did not provide any corresponding specific implementations that the successor of the class created.

  The interface keyword produces a completely abstract class, she did not provide any specific implementation, saying that "all classes that implement the interface looks like this." Therefore, any code that uses a particular interface knows what methods the interface can be called, but only needs to know can be.

  Personal understanding:

  abstract base class methods have been implemented to allow the presence and "abstract" method, which is dug pits, derived class inherits the abstract class will need to fill these pits. However, the method could be implemented in the base class to derived class has been seen.

  interface the interface is all dug pit, who will implement the interface, who will fill these pits. In addition to the pit there is no other hidden things. In other words, the interface is like an agreement between class and class.

   

  ※ However, the interface not only makes an extremely abstract class, because she allows people to achieve some by creating a similar transformation can be up to more types of the base class multiple inheritance characteristics variants ""

 

  Interface -

    Interface may comprise domains, these domains are implicitly static and final.

      For example: interface Instrument {int VALUE = 5} is less static and final VALUE

    Statement interface methods that can be displayed for the public, but even if you do not, they are also the public.

    ※ root class Object methods that appear in the interface without writing, such as toString () ;.

 

 

  Interface to expand through inheritance -

    In general, it is only possible for single entends class, but may refer to multiple interfaces. (Class can only have a "parent", and the interface can have many)

     如: interface Vampire extends Danger,Lethal{

          void drink blood ();

        }

    ※ small trap: the combination of the interface is the name conflict occurs, a combination of different interfaces intended to use the same method name often cause confusion readability of the code, so please avoid these situations. But exactly the same way and without problems.

 

  Nesting Interface -

    Class or interface may be nested within other interfaces, is added as a new way, because the interface can be implemented as a private. The point here to view

 

  Interface domain -

    As mentioned above, too, whatever you put interface domains are automatically static and final, so the interface becomes a very convenient tool for creating groups of constants.

public interface Months{
int JANUARy=1,FEBRUARY=2,MARCH=3,APRIL=4,MAY=5,JUNE=6,JULY=7,AUGUST=8,SEPTEMBER=9,OCTOBER=10,NOVEMBER=11,DECEMBER=12;            
}

    Of course, now you can use the more powerful and flexible enum keyword, but in reading the old code, you have the possibility of meeting this ancient usage.

Guess you like

Origin www.cnblogs.com/YFEYI/p/12170824.html