Object-oriented (Interface), object-oriented interface
/**
* Created by rabbit on 2014-07-21. blogpark. Liu pengcheng
*
* Interface: A special abstract class. When an abstract class
* Methods are abstract. This class can be expressed in the form of an interface.
*
* Class is used to define a class.
* Interface is used to define interfaces.
*
* Format features during Interface Definition
* 1. Common definitions in Interfaces: constants and abstract methods
* 2. All the members in the interface have fixed modifiers.
* Constant: public static final
* Method: public abstract
*
* Remember: all the members in the interface are public.
*
* Interface: objects cannot be created because there are abstract methods.
* Quilt implementation is required. Subclass is all abstract methods in the interface
* After implementation, the subclass can be instantiated.
* Otherwise, the subclass is an abstract class.
*
* An interface can be implemented by multiple classes, which is also a form of conversion not supported by multi-inheritance,
* JAVA supports multiple implementations.
*
*/
// Created by rabbit on 2014-07-21. Blog garden. Liu pengcheng
Interface inter
{
Public static final int NUM = 4;
Public abstract void show ();
}
Interface interA
{
Public abstract void show ();
}
Class Demo
{
Public void function (){}
}
// Created by rabbit on 2014-07-21. Blog garden. Liu pengcheng
Class Test extends Demo implements inter, interA
{
Public void show (){}
}
Interface
{
Void methodA ();
}
Interface B extends
{
Void methodB ();
}
Interface C extends B
{
Void methodC ();
}
Class D implements C
{
Public void methodA (){}
Public void methodB (){}
Public void methodC (){}
}
// Created by rabbit on 2014-07-21. Blog garden. Liu pengcheng
Public class Interface {
Public static void main (String [] args)
{
Test t = new Test ();
System. out. println (t. NUM );
System. out. println (Test. NUM );
System. out. println (inter. NUM );
D d = new D ();
}
}
// Created by rabbit on 2014-07-21. Blog garden. Liu pengcheng
What are the interfaces in the object-oriented interface?
I believe many people have such questions. We often say that methods are defined in interfaces, but there is no method implementation. Implementation classes must inherit interfaces and implement methods. but what does this mean?
In actual development, there are many modules in the project and there must be mutual references between modules. If we convert each module into an implementation class (there are no interfaces, there are several implementation classes ), every time you reference the class that must get the required method, the program looks dead.
After implementing an interface, we can set the required methods, no matter how many classes you implement, the user only needs to instantiate this interface and can use all the methods-this is in use; during the development process, the designer will list the required methods in the interface. As for the implementation, it can be assigned to different programmers for implementation in different class files.
Of course, this is only a little advantage of the interface, and it is also the most obvious experience of my three shoelaces in practical application. the idea of interfaces invented by the predecessors is much more complicated than I said, but it is enough for our programmers to use interfaces in this way ---
Who will talk about interfaces in the object-oriented interface? Interface and class
The interface refers to the "what can be done" of this thing, and the class refers to the "what" of this thing ".
Only when you know what it is can you create one (classes can be instantiated), but when you know what it can do, there is no way to create one (interfaces cannot be instantiated ), however, you can use "what can be done" to describe a "what is" (class instances can be implicitly converted to interfaces for use ).
IProgram. programInterface newprog = (IProgram. programInterface) oo; // IProgram. programInterface is an interface. Here, the oo conversion type is the interface implemented by it. That is to say, it will only apply to the content defined by this interface and cannot use other content of this class.
Newprog. ShowIt (); // This method is the interface method.