The second OC class and the second oc class
Example:
Creates a class, creates an object, calls a method, and changes the attribute value.
// Declare the class
@ Interface Person: NSObject
{
@ Public // make it possible to call member variables outside the class
Int _ weight; // weight
}
-(Void) run;
-(Void) rat :( char *) food;
@ End
// Class implementation
@ Implementation Person
-(Void) run {
_ Weight-= 2;
NSLog (@ "the weight after the step is % I", _ weight );
}
-(Void) eat :( char *) food {
_ Weight + = 10;
NSLog (@ "the weight after % s is % I", food, _ weight );
}
@ End
# Import <Foundation/Foundation. h>
Int main (){
Person * person1 = [Person new]
Person1-> _ weight = 100;
NSLog (@ "weight before meals: % I", _ weight );
[Person1 run];
NSLog (@ "weight before meals: % I", person1-> _ weight );
[Person1 eat: "steamed bread"];
Return 0;
}
How does oc determine whether an object is an instance of a subclass of a class?
If ([childObject. Parent class] isKindOfClass: [Parent class]
{
}
In OC, how does one perform subclass calling of superclass in the maimm file?
There is no way to do this in OC. If you want B to call the method of parent class. As you said, it can only be called in the print method of B.
[Super print] That is to say, B should complete its proper encapsulation. Other classes (such as main) should not care about what the print method of B has done.