4日目-継承練習
3427 ワード
//
// main.m
// 04-
//
// Created by Apple on 14/11/21.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import <Foundation/Foundation.h>
/*
:
iPhone ,
_color;
_ram;
_camera
iPhone2
iPhone ,
:
_color;
_ram;
_camera
: _flashlight;
:
*/
// CZIPhone .h
#import "CZIPhone.h"
#import "CZIPhone2.h"
int main(int argc, const char * argv[]) {
CZIPhone *iphone = [CZIPhone new];
[iphone call:@"110"];
[iphone takePhoto];
CZIPhone2 *iphone2 = [CZIPhone2 new];
[iphone2 call:@"10086"];
//
// [iphone2 light];
[iphone2 takePhoto];
return 0;
}
//
// CZIPhone.h
// 1121-
//
// Created by Apple on 14/11/21.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import <Foundation/Foundation.h>
/*
iPhone ,
_color;
_ram;
_camera
*/
//
//enum _CZColor{
// CZColorWhite,//
// CZColorBlack//
//};
//
////
//typedef enum _CZColor CZColor;
//
typedef enum _CZColor{
CZColorWhite,//
CZColorBlack//
} CZColor;
@interface CZIPhone : NSObject
{
CZColor _color;//
int _ram;//
NSString *_camera;// :800
}
//
- (void) setColor:(CZColor) color;
- (CZColor) color;
- (void) setRam:(int) ram;
- (int) ram;
- (void) setCamera:(NSString *) camera;
- (NSString *) camera;
// setter getter
//
- (void) call:(NSString *) phoneNum;
//
- (void) takePhoto;
@end
//
// CZIPhone.m
// 1121-
//
// Created by Apple on 14/11/21.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import "CZIPhone.h"
@implementation CZIPhone
//
- (void) setColor:(CZColor) color
{
_color = color;
}
- (CZColor) color
{
return _color;
}
- (void) setRam:(int) ram
{
_ram = ram;
}
- (int) ram
{
return _ram;
}
- (void) setCamera:(NSString *) camera
{
_camera = camera;
}
- (NSString *) camera
{
return _camera;
}
// setter getter
//
- (void) call:(NSString *) phoneNum
{
NSLog(@"CZIPhone %@ !",phoneNum);
}
//
- (void) takePhoto
{
NSLog(@"CZIPhone takePhoto");
}
@end
//
// CZIPhone2.h
// 1121-
//
// Created by Apple on 14/11/21.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import "CZIPhone.h"
// , :
/*
iPhone2
iPhone ,
:
_color;
_ram;
_camera
: _flashlight;
:
*/
@interface CZIPhone2 : CZIPhone
{
BOOL _flashlight;// ,YES ,NO
}
- (void) light;
// ,
@end
//
// CZIPhone2.m
// 1121-
//
// Created by Apple on 14/11/21.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import "CZIPhone2.h"
@implementation CZIPhone2
- (void) light
{
if (_flashlight == NO) {
NSLog(@" ");
_flashlight = YES;
}else{
NSLog(@" ");
}
}
// ,
- (void) takePhoto
{
//
[self light];
//
// super ,
// , super
[super takePhoto];
_flashlight = NO;
NSLog(@" !");
}
@end