Java in Java interface is ' interface ' meaning, and Java class declaration with class, that is, interface with interface declaration, class is declared with class, is two separate parts.
Only when a class declares to implement an interface do they establish a relationship, for example:
[HTML]View Plaincopyprint?
- Interface ai{
- void print ();
- };
- Class ac{
- };
At this time, the AI and AC are independent, AC does not have to build a relationship with the AI to compile the error, the following modifications to the AC, the AI to establish a relationship with AC, AC must implement the method declared in the AI to compile.
[HTML]View Plaincopyprint?
- Class AC Implement ai{
- void print () {
- System.out.println (' Hello world ');
- }
- };
objective-cOn the internet everyone will be in OC interface understood as "informal agreement (or interface)", Prototal understood as "formal agreement (or interface)", I think it is not difficult to understand, but very twisted, so I do a bit of their own understanding:
1, protocal is equivalent to Java in the interface;
2, while interface and implementation together represent a class, the combination of the two is equivalent to the class in Java, that is, the class in OC must consist of two parts, interface part and implementation part, This is the complete declaration of a class in OC, and then the declaration portion of the member variable and the member method is placed in the interface section of the OC, including the inheritance relationship, protocal implementation of the relationship, all in the interface inside the head to declare, Then put the implementation part in the implementation section, equivalent to split the class into declarations and implementation of two parts, which is indispensable, so in OC, may not be called the interface interface, directly called the class declaration part comes easy to understand more, in short, Interface in OC is a part of the class, and implementation together to form a complete class. In addition to the OC we can define in the @interface can also be defined in the property variables, what is the difference between the two?
- If you define variables only in @nterface, the variables you define can only be accessed in the current class, not in other classes, and variables declared with @property may be accessed externally.
- Using @property to declare variables, you can use the "self. Variable name" method to read and write variables. And the way to use @interface is not possible.
- Here is a link: http://stackoverflow.com/questions/9702258/ Difference-between-properties-and-variables-in-ios-header-file want to see it more clearly.
The difference between @interface and Java in OC and the @implementation @protocol