Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Inheritance Example
//gcc 5.0.4 #import <Foundation/Foundation.h> @interface Car:NSObject{ CGFloat price; NSString *fuelType; NSInteger engine; NSString *model; NSInteger seatingCapacity; } - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType; - (void) print; @end @implementation Car - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType { model = Model; price = Price; seatingCapacity=SeatingCapacity; fuelType=FuelType; engine=Engine; return self; } - (void) print { NSLog(@"Model: %@", model); NSLog(@"Price: Rs. %f lakhs", price); NSLog(@"Engine: %ld cc", engine); NSLog(@"Fuel Type: %@", fuelType); NSLog(@"Seating Capacity: %ld", seatingCapacity); } @end @interface RenaultKwid :Car{ NSInteger speed; } - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSpeed:(NSInteger)Speed andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType; - (void) print; @end @implementation RenaultKwid - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSpeed:(NSInteger)Speed andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType { model = Model; price = Price; seatingCapacity=SeatingCapacity; fuelType=FuelType; engine=Engine; speed=Speed; return self; } - (void) print { NSLog(@"showing RenaultKwid %@ model details",model); NSLog(@"Price: Rs. %f lakhs", price); NSLog(@"Engine: %ld cc", engine); NSLog(@"Speed: %ld kmph",speed); NSLog(@"Fuel Type: %@", fuelType); NSLog(@"Seating Capacity: %ld", seatingCapacity); } @end @interface MarutiSantro:Car - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType; - (void) print; @end @implementation MarutiSantro - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType { model = Model; price = Price; seatingCapacity=SeatingCapacity; fuelType=FuelType; engine=Engine; return self; } - (void) print { NSLog(@"showing MarutiSantro %@ model details",model); NSLog(@"Price: Rs.%f lakhs", price); NSLog(@"Engine: %ld cc", engine); NSLog(@"Fuel Type: %@", fuelType); NSLog(@"Seating Capacity: %ld", seatingCapacity); } @end @interface MarutiDzire :Car - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType; - (void) print; @end @implementation MarutiDzire - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType { model = Model; price = Price; seatingCapacity=SeatingCapacity; fuelType=FuelType; engine=Engine; return self; } - (void) print { NSLog(@"showing MarutiDzire %@ model details",model); NSLog(@"Price: Rs.%f lakhs", price); NSLog(@"Engine: %ld cc", engine); NSLog(@"Fuel Type: %@", fuelType); NSLog(@"Seating Capacity: %ld", seatingCapacity); } @end @end @interface MarutiErtisa:Car - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType; - (void) print; @end @implementation MarutiErtisa - (id)initWithModel:(NSString *)Model andPrice:(CGFloat)Price andEngine:(NSInteger)Engine andSeatingCapacity:(NSInteger)SeatingCapacity andFuelType:(NSString *)FuelType { model = Model; price = Price; seatingCapacity=SeatingCapacity; fuelType=FuelType; engine=Engine; return self; } - (void) print { NSLog(@"showing MarutiErtisa %@ model details",model); NSLog(@"Price: Rs.%f lakhs ", price); NSLog(@"Engine: %ld cc", engine); NSLog(@"Fuel Type: %@", fuelType); NSLog(@"Seating Capacity: %ld", seatingCapacity); } @end int main (int argc, const char * argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; RenaultKwid *car = [[RenaultKwid alloc]initWithModel:@"STD" andPrice:2.61 andEngine:799 andSpeed:135 andSeatingCapacity:5 andFuelType:@"Petrol"]; [car print]; MarutiSantro *car1 = [[MarutiSantro alloc]initWithModel:@"Sportz" andPrice:5.02 andEngine:1086 andSeatingCapacity:5 andFuelType:@"Petrol"]; [car1 print]; [pool drain]; return 0; }
run
|
edit
|
history
|
help
0
arary
NSMutableset(add/remove,Etraction,Intersect)
Objective C NSSet Declaration
Author1
Objective C NSSet Declaration
aditation
basic arithmatic Opreation in objective C
book
NSString Examples in one
find maximum in objective c