本帖最后由 heima-王鹏 于 2014-4-23 20:12 编辑
- #import <Foundation/Foundation.h>
- //需求:定义一个成绩类,C语言成绩,OC成绩,总成绩(只读)
- @interface Score:NSObject
- { int _cScore;
- int _ocScore;
- int _totalScore;
- double _averageScore;
- }
- - (void)setCScore:(int)cScore;
- - (void)setOcScore:(int)ocScore;
- - (int)cScore;
- - (int)ocScore;
- - (int)totalScore;
- @end
- @implementation Score
- - (void)setCScore:(int)cScore
- {
- _cScore = cScore;
- <font color="#ff0000"> //_totalScore = _cScore + _ocScore;</font>
- }
- - (void)setOcScore:(int)ocScore
- {
- _ocScore = ocScore;
- <font color="#ff0000"> //_totalScore = _cScore + _ocScore;</font>
- }
- - (int)cScore
- {
- return _cScore;
- }
- - (int)ocScore
- {
- return _ocScore;
- }
- - (int)totalScore;
- {
- return _cScore + _ocScore;<font color="#ff0000">// _totalScore;</font>
- }
- int main ()
- { Score *s = [Score new];
- [s setCScore:80];
- [s setOcScore:90];
- [s setCScore:90];
- int a = [s totalScore];
- NSLog(@"总成绩=%d",a);
- return 0;
- }
复制代码 问题:如代码中return _cScore + _ocScore;和 在代码中添加//_totalScore = _cScore + _ocScore;return _totalScore;有什么区别?试了几次好像都没什么区别,但视频中老师说有区别,搞不懂了到底有什么区别?
|