OC2-重写
//
// Dog.h
// OC2-重写
//
// Created by qianfeng on 15/6/17.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "Animal.h" @interface Dog : Animal
{
float _weight;
}
@property (assign,nonatomic)float weight;
@end //
// Dog.m
// OC2-重写
//
// Created by qianfeng on 15/6/17.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "Dog.h"
//重写父类的继承过来的方法,不需要再次声明
@implementation Dog
-(void)printAnimalInformation
{
NSLog(@"name=%@,age=%i,,weight=%.2f",_name,_age,_weight);
}
-(void)showAnimalFood
{
NSLog(@"%@_____",[self class]);
}
@end
//
// Animal.h
// OC2-重写
//
// Created by qianfeng on 15/6/17.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <Foundation/Foundation.h> @interface Animal : NSObject
{
NSString *_name;
int _age; }
@property (copy,nonatomic)NSString *name;
@property(assign,nonatomic)int age;
-(void)showAnimalFood;
-(void)printAnimalInformation;
@end //
// Animal.m
// OC2-重写
//
// Created by qianfeng on 15/6/17.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "Animal.h" @implementation Animal
-(void)showAnimalFood
{
NSLog(@"%@_____",[self class]);
}
-(void)printAnimalInformation
{
NSLog(@"name=%@,age=%i",_name,_age);
}
@end
//
// main.m
// OC2-重写
//
// Created by qianfeng on 15/6/17.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <Foundation/Foundation.h>
#import "Dog.h"
#import "Animal.h"
int main(int argc, const char * argv[]) {
@autoreleasepool { Dog *xiaobai =[[Dog alloc] init];
xiaobai.name=@"";
xiaobai.age=;
xiaobai.weight=; [xiaobai printAnimalInformation];
[xiaobai showAnimalFood]; Animal *xiaohei =[[Animal alloc] init];
xiaohei.name=@"xiaohei";
xiaohei.age=;
[xiaohei printAnimalInformation];
[xiaohei showAnimalFood]; }
return ;
}
OC2-重写的更多相关文章
- .NET 基础 一步步 一幕幕[面向对象之方法、方法的重载、方法的重写、方法的递归]
方法.方法的重载.方法的重写.方法的递归 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值 ...
- category中重写方法?
问:可以在category中重写方法吗? 答:代码上可以实现 在category中重写方法,但在实际开发中,不建议这样做.如果确实需要重写原有方法也建议使用子类进行重写. category是为了更方便 ...
- ASP.NET Aries 4.0 开源发布:已完成基础功能优化重写
主要更新: 1:增加AR.Global.GetUser() 方法返回当前登陆者的用户信息. 2:重写AR.Combobox 支持下拉树. 3:调整及扩展Input下拉的配置参数. 4:优化及新增AR. ...
- 小丁带你走进git的世界四-重写历史记录
一.git对象文件创建 开篇先补充一个知识点,就是比如我建立一个文件之后,使用git add就会生成一个git对象,但是git对象生成后可以在.git/objects里面对应,首先我们来初始化一个仓库 ...
- 已经重写,源码和文章请跳转http://www.cnblogs.com/ymnets/p/5621706.html
文章由于写得比较仓促 已经重写,源码和文章请跳转 http://www.cnblogs.com/ymnets/p/5621706.html 系列目录 前言: 导入导出实在多例子,很多成熟的组建都分装了 ...
- C#基础回顾(二)—页面值传递、重载与重写、类与结构体、装箱与拆箱
一.前言 -孤独的路上有梦想作伴,乘风破浪- 二.页面值传递 (1)C#各页面之间可以进行数据的交换和传递,页面之间可根据获取的数据,进行各自的操作(跳转.计算等操作).为了实现多种方式的数据传递,C ...
- SQL Server索引视图以(物化视图)及索引视图与查询重写
本位出处:http://www.cnblogs.com/wy123/p/6041122.html 经常听Oracle的同学说起来物化视图,物化视图的作用之一就是可以实现查询重写,听起来有一种高大上的感 ...
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
转载:http://freeloda.blog.51cto.com/2033581/1288553 大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负 ...
- Storm中遇到的日志多次重写问题(一)
业务描述: 统计从kafka spout中读取的数据条数,以及写入redis的数据的条数,写入hdfs的数据条数,写入kafaka的数据条数.并且每过5秒将数据按照json文件的形式写入日志.其中保存 ...
- 重写ValidateEntity虚方法实现可控的上下文验证和自定义验证
上篇文章介绍了ValidationAttribute和IValidatableObject.Validate验证,但是这种验证还是稍微简单了,对于复杂的实体,例如:继承过来的实体.实现某接口的实体等等 ...
随机推荐
- uva 11983 Weird Advertisement 扫描线
Weird Advertisement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/probl ...
- HDU 5510 Bazinga 暴力匹配加剪枝
Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...
- HDU 4821 String hash
String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 【PAT Advanced Level】1008. Elevator (20)
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...
- [MEAN Stack] First API -- 4. Organize app structure
The app structure: Front-end: app.js /** * Created by Answer1215 on 12/9/2014. */ 'use strict'; func ...
- 【Github教程】史上最全github用法:github入门到精通
原文 http://www.eoeandroid.com/thread-274556-1-1.html [初识Github] 首先让我们大家一起喊一句"Hello Github". ...
- Haproxy+MYSQL 负载均衡 原创
[root@monitor app1]# yum install haproxy Loaded plugins: security : epel | : epel/primary_db | : ext ...
- 基础笔记(一)Java 集合
集合日常用到的有List,Set,Map等等. List List常用的有2种,包括ArrayList与LinkedList.这两种List的主要区别在于底层的数据结构的差别.ArrayList是基于 ...
- 10+ commonly using find command switches with example Unix/Linux
http://crybit.com/find-command-usage-with-example-unixlinux/ find command is one of the best search ...
- Codec工具类
import java.math.BigInteger; import org.apache.commons.codec.DecoderException; import org.apache.com ...