I. Inheritance of Classes
In objective-C, class inheritance is similar to that in C ++. The difference is that objective-C does not support multiple inheritance. A class can only have one parent class, single inheritance makes the inheritance relationship of objective-C simple and easy to manageProgram.
In objective-C, the parent class of all classes is nsobject.
Example of class inheritance in objective-C:
@ Interface person: nsobject {nsstring * Name; int age;}-(nsstring *) Name;-(INT) age;-(void) setname: (nsstring *) input; -(void) setage: (INT) input; @ end;
Ii. Method Rewriting
In objective-C, subclass can inherit the methods in the parent class, instead of re-writing the same method, you can directly use the methods of the parent class.
But sometimes we don't want to use the parent class method, but want to make some changes. What should we do? You can overwrite the methods of the parent class by writing a method name, return type, and parameter in the subclass that has the same name as the parent class. Relatively simple.
Iii. Method Overloading
In objective-C, methods cannot be overloaded. That is to say, we cannot define two methods in the class: they have the same name, the same number of parameters, different parameter types, and different return value types. Otherwise, xcode reports an error.
The method defined below is incorrect:
-(Void) setx :( INT) intx;-(void) setx :( double) doublex;
This part is much simpler than C ++.