I. Inheritance of classes
The inheritance of classes in objective-c is similar to C + +, except that OBJECTIVE-C does not support multiple inheritance, a class can have only one parent class, and single inheritance makes Objective-c's inheritance relationship simple and easy to administer.
The parent class of all classes in Objective-c is NSObject.
Examples of inheritance of classes in Objective-c:
[CPP]View Plaincopy
- @interface Person:nsobject {
- nsstring* name;
- int age;
- }
- -(nsstring*) name;
- -(int) age;
- -(void) SetName: (nsstring*) input;
- -(void) Setage: (int) input;
- @end;
Second, Method rewrite
In Objective-c, subclasses can inherit methods from the parent class without having to rewrite the same method, directly using the parent class's methods.
But sometimes we do not want to use the parent method, but want to make some changes, how to do? As long as you write a subclass with the same method name, return type, and arguments as the parent class, you can override overrides for the parent class's methods. relatively simple.
Third, method overloading
In Objective-c, methods are not overloaded. That is, we cannot define two methods in the class: their names are the same, the number of parameters is the same, the parameter types are different, and the return value types are different. Otherwise, Xcode will make an error.
The methods defined below are incorrect:
[CPP]View Plaincopy
- -(void) SetX: (int) IntX;
- -(void) SetX: (double) DoubleX;
This part is a lot simpler than C + +.
Inheriting methods for the Objective-c class overriding method overloads