Created
January 15, 2015 18:12
-
-
Save imack/5745921344cc80bf926b to your computer and use it in GitHub Desktop.
Basic OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// W1D4 | |
// | |
// Created by Ian MacKinnon on 2015-01-15. | |
// Copyright (c) 2015 Ian MacKinnon. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface Student : NSObject | |
-(int) howManyHoursOfSleep; | |
-(int) howManyActualHoursOfSleep:(int)claimed; | |
-(void) sayHello; | |
@end | |
@implementation Student | |
-(void) speakFromHeart{ | |
NSLog(@"It's week 5 and I question reality"); | |
} | |
-(int) howManyHoursOfSleep{ | |
[self speakFromHeart]; | |
return 6; | |
} | |
-(int) howManyActualHoursOfSleep:(int)claimed{ | |
return claimed + 2; | |
} | |
-(void) sayHello{ | |
NSLog(@"Hello, I got %d hours of sleep last night", [self howManyHoursOfSleep]); | |
} | |
@end | |
@interface CoolStudent : Student | |
@end | |
@implementation CoolStudent | |
-(void) sayHello{ | |
NSLog(@"'sup, I got %d hours of sleep last night", [self howManyHoursOfSleep]); | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
// insert code here... | |
Student *student = [[CoolStudent alloc] init]; | |
[student sayHello]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment