objective-c 之类的声明与调用(2021-11-10)

//
//  main.m
//  hello
//  Created by 老米 on 2021/11/10.
//

#import <Foundation/Foundation.h>
//类的声明
@interface Student : NSObject
{
    //类的属性声明
    NSString *name;
    int age;
}
//类方法声明
-(void)say;
@end

@implementation Student
//类方法实现
-(void)say
{
    NSLog(@"Hello, World!");
}
@end


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Student *laomi=[[Student alloc]init];//类实例化对象
        [laomi say];//对象调用类方法
    }
    return 0;
}
上一篇:VM16+Centos7配置boost库


下一篇:19. 面向对象之多态、鸭子类型、抽象类