//

//  main.m

//  OCbasic1

//

//  Created by apple on 14-8-5.

//  Copyright (c) 2014年 苹果IOS软件开发者. All rights reserved.

//

#import <Foundation/Foundation.h>

#import "Dog.h"

int main(int argc, const char * argv[]) {

@autoreleasepool {

// insert code here...

NSLog(@"Hello, World!");

//write code here.

Dog *dog = [[Dog alloc] init];

//创建一个dog对象并初始化

//定义参数,调用方法

int ID = [dog getID];

int age = [dog getage];

float price = [dog getprice];

printf("dog ID: %d age: %d price: %f\n",ID,age,price);

//dog ID: 1 age: 2 price: 60.000000

Dog *dog2 = [[Dog alloc ]initWithID:20 andage:5 andprice:100.88];

ID =[dog2 getID];

age = [dog2 getage];

price = [dog2 getprice];

printf("dog2 ID: %d age: %d price: %f\n",ID,age,price);

//dog2 ID: 20 age: 5 price: 100.879997    return 0;

[dog2 setID:19 andage:4 andprice:86.8];

ID =[dog2 getID];

age = [dog2 getage];

price = [dog2 getprice];

printf("dog2 ID: %d age: %d price: %f\n",ID,age,price);    }

}

//

//  Dog.h

//  OCbasic1

//

//  Created by apple on 14-8-5.

//  Copyright (c) 2014年 苹果IOS软件开发者. All rights reserved.

//

#import <Foundation/Foundation.h>

@interface Dog : NSObject

{

//字段(成员变量)及其访问权限

@protected

int ID;

@public

int age;

@private

float price;

}

//凡是以initXX开头的都是构造函数

- (id) init;

//函数名为init,不带参数

- (id) initWithID:(int)newID;

//函数名为initWith:,带一个int的参数

- (id) initWithID:(int)newID andage:(int)newage;

//函数名为initWithID:andage:,带两个int参数

- (id) initWithID:(int)newID andage:(int)newage andprice:(float)newprice;

//函数名为initWithID:andage:andprince

- (void) setID:(int)newID;

- (int) getID;

//set/get ID

- (void) setage:(int)newage;

- (int) getage;

//set/get age

- (void) setprice:(float)newprice;

- (float) getprice;

//set/get price

- (void) setID:(int)newID andage:(int)newage;

// setID:andage:两个参数

- (void) setID:(int)newID andage:(int)newage andprice:(float)newprice;

// setID:andage:andprice: 3个参数

@end

//

//  Dog.m

//  OCbasic1

//

//  Created by apple on 14-8-5.

//  Copyright (c) 2014年 苹果IOS软件开发者. All rights reserved.

//

#import "Dog.h"

@implementation Dog

- (id)init

{

return [self initWithID:1 andage:2 andprice:60.0];

//    self = [super init];

//    // super表示父类

//    // self 表示对象自己

//    if (self)

//    {

//        ID = 1;

//        age = 2;

//        price = 60.0f;

//    }

//    return self;

}

- (id)initWithID:(int)newID

{

return [self initWithID:newID andage:2];

//    self = [super init];

//    if (self) {

//        ID = newID;

//        age = 2;

//        price = 60.0f;

//    }

//    return self;

}

- (id)initWithID:(int)newID andage:(int)newage

{

return [self initWithID:newID andage:newage andprice:60.0f];

//    self = [super init];

//    if (self) {

//        ID = newID;

//        age = newage;

//        price = 60.0f;

//    }

//    return self;

}

- (id)initWithID:(int)newID andage:(int)newage andprice:(float)newprice

{

self = [super init];

if (self) {

ID = newID;

age = newage;

price = newprice;

}

return self;

}

- (void)setID:(int)newID

{

ID = newID;

}

- (int)getID

{

return ID;

}

- (void)setage:(int)newage

{

age = newage;

}

- (int)getage

{

return age;

}

- (void)setprice:(float)newprice

{

price = newprice;

}

- (float)getprice

{

return price;

}

- (void)setID:(int)newID andage:(int)newage

{

ID = newID;

age = newage;

}

- (void)setID:(int)newID andage:(int)newage andprice:(float)newprice

{

ID = newID;

age = newage;

price = newprice;

}

@end

Object-c基本语法的更多相关文章

  1. 终于懂了:Delphi的函数名不是地址,取地址必须遵守Object Pascal的语法(Delphi和C的类比:指针、字符串、函数指针、内存分配等)good

    这点是与C语言不一样的地方,以前我一直都没有明白这一点,所以总是不明白:函数地址再取地址算怎么回事? ------------------------------------------------- ...

  2. Java提高学习之Object类详解(1)

    转自:http://www.importnew.com/10304.html 问:什么是Object类? 答:Object类存储在java.lang包中,是所有java类(Object类除外)的终极父 ...

  3. Object C和C#的差异

    从C#到Object C,循序渐进学习苹果开发(1)--准备开发账号和开发环境 本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台开发苹果开发的一系列感想和体验历程,本系列文章是在起步 ...

  4. JS apply的巧妙用法以及扩展到Object.defineProperty的使用

    Math.max 实现得到数组中最大的一项 var array = [1,2,3,4,5]; var max = Math.max.apply(null, array); console.log(ma ...

  5. 深入理解 Object.defineProperty 及实现数据双向绑定

    Object.defineProperty() 和 Proxy 对象,都可以用来对数据的劫持操作.何为数据劫持呢?就是在我们访问或者修改某个对象的某个属性的时候,通过一段代码进行拦截行为,然后进行额外 ...

  6. day 50 js-part1基础语法,数据类型及用法,流程控制语句,循环

    js基本概念: JavaScript 是世界上最流行的脚本语言. JavaScript 被数百万计的网页用来改进设计.验证表单.检测浏览器.创建cookies,以及更多的应用. JavaScript ...

  7. Object C学习笔记10-静态方法和静态属性

    在.NET中我们静态使用的关键字static有着举足轻重的作用,static 方法可以不用实例化类实例就可以直接调用,static 属性也是如此.在Object C中也存在static关键字,今天的学 ...

  8. iOS 开发系列:CoreData Object 变成 Fault 的一种方式

    @quote: 近来一直与 CoreData 打交道.这是一个架构庞大.学习曲线比較陡峭的 iOS 组件,每次遇到问题都会对其有新的认识. 这次就仅仅讲一点,关于错误认知 Object(NSManag ...

  9. Java:Object类详解

    Java的一些特性会让初学者感到困惑,但在有经验的开发者眼中,却是合情合理的.例如,新手可能不会理解Object类.这篇文章分成三个部分讲跟Object类及其方法有关的问题. 上帝类 问:什么是Obj ...

  10. Android学习笔记_46_Android的intent之间Object、List、List<Object>和全局变量数据的传递(Parcelable Serializable)

    转http://blog.csdn.net/pku_android/article/details/7456305 一.传递List<String>和List<Integer> ...

随机推荐

  1. C#性能优化总结

    1. C#语言方面 1.1 垃圾回收 垃圾回收解放了手工管理对象的工作,提高了程序的健壮性,但副作用就是程序代码可能对于对象创建变得随意. 1.1.1 避免不必要的对象创建 由于垃圾回收的代价较高,所 ...

  2. windows服务命令 转载

    OnCustomCommand executes when the Service Control Manager (SCM) passes a custom command to the servi ...

  3. 安装Microsoft SQL server Management Studio Express 2005 错误码是29506解决方案

    安装Microsoft SQL server Management Studio Express 2005,安装程序在安装此软件包时遇到一个错误,这可能表示此软件包有错.错误码是29506”权限问题. ...

  4. Python开发工具Atom

    python基础教程之Python开发工具Atom   本节内容如下: Atom简介 下载安装Atom 安装Python开发包 使用Atom开发Python程序 Atom简介 Atom是Github开 ...

  5. IIS7.0 下使用Intelligencia.UrlRewriter时Session为空问题

    背景 新年伊始,本人的开发环境由Windows Server 2003 +IIS 6 升级成了 Windows Server 2008 +IIS 7,之后便着手参加新项目的开发.项目开发后期测试过程中 ...

  6. gerrit配置和使用

    参考http://www.cnblogs.com/tesky0125/p/5973642.html 1.安装gerrit replication插件 mkdir ~/tmp cp gerrit-2.1 ...

  7. consul-template + nginx部署高可用负载均衡

    一.Consul-Template简介 Consul-Template是基于Consul的自动替换配置文件的应用.在Consul-Template没出现之前,大家构建服务发现系统大多采用的是Zooke ...

  8. 廖雪峰Java3异常处理-2断言和日志-3使用Commons Logging

    Commons Logging是Apache创建的日志模块: 可以挂接不同的日志系统 可以通过配置文件指定挂接的日志系统 自动搜索并使用Log4j 如果Log4j不存在,使用JDK Logging(J ...

  9. kubernetes k8s yum localinstall

    localinstall 是安装在本地的rpm包顺便解决依赖关系 yum localinstall docker-common-1.12.6-68.gitec8512b.el7.centos.x86_ ...

  10. 视角同步NewViewTarget

    SetViewTargetwithBlen说明: http://api.unrealengine.com/INT/BlueprintAPI/Game/Player/SetViewTargetwithB ...