--- Java training, Android training, IOS training, and. Net training. We look forward to communicating with you! ---
Design two classes and write out the set get method corresponding to the attribute (write method only)
1> Vehicle
(1) attributes
* Number of wheels
* Speed
(2) Method
* Set and get methods corresponding to the attribute
The Code is as follows:
1 // setter getter Declaration 2-(void) setwheels: (INT) wheels; 3-(INT) wheels;
1 // setter getter implementation 2-(void) setwheels; (INT) wheels3 {4 _ wheels = wheels; 5} 6-(INT) wheels7 {8 return _ wheels; 9}
2> Persons
(1) attributes
* Name
* Age
* Height
(2) Method
* Set and get methods corresponding to the attribute
The Code is as follows:
// Setter getter Declaration-(void) setname: (nsstring *) Name;-(void) setage: (INT) age;-(INT) age;-(void) setheight: (double) height;-(double) height; // setter getter implementation-(void) setname: (nsstring *) name {_ name = Name;}-(nsstring *) name {return _ name;}-(void) setage: (INT) Age {_ age = age ;} -(INT) Age {return _ age;}-(void) setheight: (double) height {_ Height = height;}-(double) height {return _ height ;}
Black Horse programmer 04-set get method exercises