Skip to content

Instantly share code, notes, and snippets.

@imack
Created January 15, 2015 18:12
Show Gist options
  • Save imack/5745921344cc80bf926b to your computer and use it in GitHub Desktop.
Save imack/5745921344cc80bf926b to your computer and use it in GitHub Desktop.
Basic OOP
//
// 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