Today I learned inheritance, attributes, and polymorphism.
Assignment: Animal parent, cat child, lion and grandson;
# Import <Foundation/Foundation. h> @ interface animal: nsobject @ end // animal class # import <Foundation/Foundation. h> @ interface animal: nsobject @ end // animal class # import "animal. H "@ interface feline: Animal-(void) eyes;-(void) tail;-(void) flid; @ end // cat type # import" animal. H "@ interface feline: Animal-(void) eyes;-(void) tail;-(void) flid; @ end // cat type # import" feline. H "@ interface LION: Feline-(void) character;-(void) body; @ end // lion class # import" Lion. H "@ implementation lion-(void) character {nslog (@" % @ ", @" Lion character fierce and cruel "); // fierce character}-(void) body {nslog (@ "% @", @ "Lion a strong"); // body strong} @ end // lion class # import "viewcontroller. H "# import" Lion. H "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib. animal * animal; feline * feline; // defines the object feline = [[feline alloc] init]; // initializes [feline flid]; // prints the behavior [feline eyes]; [feline tail]; [feline release]; lion * lion; lion = [[Lion alloc] init]; [Lion character]; [lion body];}-(void) didreceivememorywarning {[Super didreceivememorywarning]; // dispose of any resources that can be recreated .} @ end
Objective-C Lesson 2