------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
类: 一类事物共同特征和行为的抽象
大卡车 小轿车 三轮车
车类:Car
共同的特征:颜色 速度 轮子
共同的行为:跑 停止
对象: 类的具体的个体
解放车 (车类的对象)
东风车 (车类的对象)
奥迪车 (车类的对象)
时风车 (车类的对象)
类的定义:
结构体的定义:
struct Student{
int age;
char *name;
}; --->定义一个Student 结构体
类的定义分为两部分:
1)类的声明(规定当前类得:类名、属性、行为)
@interface 类名:父类名
{
//定义类的属性
}
//类的行为
@end
2)类的事项(实现具体行为)
@implementation 类名
//行为的具体实现
@end
#import <Foundation/Foundation.h>
//车的类的声明
@interface Car:NSObject
{
//类的属性
int lunzi; //车的轮子
NSString *color; //车的颜色
int speed; //车的速度
}
//类的行为
@end
//类的实现
@implementation Car
//行为的具体描述
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}