- #import <Foundation/Foundation.h>
- //类的声明
- #pragma mark 学生信息
- @interface Student : NSObject
- {
- @public
- //命名规范 _变量名
- NSString * _name; //姓名
- int _num; //学号
- int _age; //年龄
- }
- //类的行为
- -(void)speak;//无参无返回值
- @end
- //类的实现
- @implementation Student
- //-(void)speakName:(NSString *)name andNum: (int) num andAge:(int) age;
- -(void)speak
- {
- NSLog(@"我的姓名是%@,我的学号是%d,我的年龄是%d",_name,_num,_age);
- }
- @end
- int main() {
- @autoreleasepool {
- Student * stu = [Student new];
- stu->_name=@"xiaolong";
- stu->_num=123456;
- stu->_age=23;
- [stu speak];
-
- }
- return 0;
- }
复制代码- #import <Foundation/Foundation.h>
- //类的声明
- #pragma mark 学生信息
- @interface Student : NSObject
- {
- @public
- //命名规范 _变量名
- NSString * _name; //姓名
- int _num; //学号
- int _age; //年龄
- }
- //类的行为
- -(void)speakName:(NSString *)name andNum: (int) num andAge:(int) age;//有参无返回值
- @end
- //类的实现
- @implementation Student
- -(void)speakName:(NSString *)name andNum: (int) num andAge:(int) age
- {
- NSLog(@"我的姓名是%@,我的学号是%d,我的年龄是%d",name,num,age);
- }
- @end
- int main() {
- @autoreleasepool {
- Student * stu = [Student new];
- [stu speakName:@"xiaolong" andNum:123456 andAge:23];
- }
- return 0;
- }
复制代码
|