Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
inheritenace-test
//gcc 5.0.4 #import <Foundation/Foundation.h> @interface Square:NSObject { //Instance variables double length; } @property(nonatomic, readwrite) double length; // Property @end @interface Rectangle:Square { //Instance variables double width; double height; } @property(nonatomic, readwrite) double width; @property(nonatomic, readwrite) double height; @end @implementation Square @synthesize length; -(id)init { self = [super init]; length = 1.0; return self; } -(void) funcX { NSLog(@"My length is %f", length); } -(double) area { return length * length; } @end @interface Square3M:Square { } @end @implementation Rectangle @synthesize width; @synthesize height; -(id)init { self = [super init]; width = 1.0; height = 1.0; return self; } -(void) funcX { NSLog(@"My width is %f, height is %f", width, height); } -(double) area { return width * height; } -(void) funcY { [self funcX]; [super funcX]; } @end @implementation Square3M -(id)init { self = [super init]; length = 3.0; return self; } -(void) funcZ { NSLog(@"My super length is %f", super.length); } @end int main (int argc, const char * argv[]) { NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init]; NSLog(@"My Square"); Square *mySquare = [[Square alloc] init]; [mySquare funcX]; NSLog(@"My Square Area is = %f", [mySquare area]); [mySquare autorelease]; NSLog(@"My Rect"); Rectangle *myRect = [[Rectangle alloc] init]; [myRect funcX]; NSLog(@"My Rect Area is = %f", [myRect area]); [myRect funcY]; [myRect autorelease]; NSLog(@"My Square3M"); Square *mySquare3M = [[Square3M alloc] init]; [mySquare3M funcX]; NSLog(@"My Square3M Area is = %f", [mySquare3M area]); [mySquare3M funcZ]; [mySquare3M autorelease]; [myPool drain]; return 0; }
run
|
edit
|
history
|
help
0
Author1
Obj-C_Program_Structure_1
find maximum in objective c
datatype
array
Even numbers are at the beginning and all the Odd numbers
objective c find factorial
Inheritance Example
Cylinder And Circle
NSString & MutableNSString Examples in one