OC-03类的声明和实现

时间:2023-03-09 00:02:25
OC-03类的声明和实现

  

例子

//类名:Car
//属性:轮胎个数、时速
//行为:跑

#import<Foundation/Foundation.h >
//完整的写一个函数:函数的声明和定义(实现)
//完整的写一个类:类的声明和实现

1、类的声明
//声明对象的属性、行为
//NSObject 目的性:让Car这个类具备创建对象的能力(继承)
@interface Car : NSObject
{//用来声明对象属性(成员变量)
  int wheels;//轮胎个数
  int speed;//时速(xx km/h)

}
@end

2、类的实现
@implementation car

@end

int main()
{
//在OC中,想执行一些行为,就写上一个中括号[行为执行者 行为名称]
//利用类来创建对象
//执行了Car这个类的new行为来创建新对象
  [Car new];
  return 0;
}