The OBJECT-C code is divided into three parts:. h files,. m files, and call files
. h Source File
#import <Foundation/Foundation.h> @interface student:nsobject{nsstring *studentname; Nsinteger age;} -(void) printinfo;-(void) Setstudentname: (nsstring*) name;-(nsstring*) studentname;-(Nsinteger) age; @end
. m source File
#import "Student.h" @implementation student-(void) Printinfo{nslog (@ "Name:%@ Age:%d Years", studentname,studentage);} -(void) Setstudentname: (nsstring*) Name{studentname=name;} -(void) Setage: (Nsinteger) age{studentage=age;} -(nsstring*) Studentname{return studentname;} -(Nsinteger) Age{return studentage;} @end
Call source file
Student *student=[[student Alloc]init]; Init is the equivalent of instantiating [student setstudentname:@ "Zhang San"]; [Student Setage:10]; [Student Printinfo]; [Student release]; Resource release
Summary of instance methods and constructors
Object-c classes, methods, constructors (2)