免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2648 | 回复: 0
打印 上一主题 下一主题

Add Methods To Class [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-09 18:06 |只看该作者 |倒序浏览
Add Methods To Class

Introduce Eclipse Views and Perspectives
Introduce Eclipse user interface – drag / drop, cnntext menus, help
Add get and set methods to Person class
1. 自动提示或补充标识符。

    英文版的系统用Ctrl+Space, 中文版的系统用Alt+/。

2. Parameters and Fields.

3. this

    this = the current object

4. Class members
  1.     1> Fields for data.

  2.     2> Constructors to create objects.

  3.     3> Methods. e.g.. getters , setters.


  4. 1 package org.totoalbeginner.tutorial;
  5. 2  
  6. 3  public class Person {
  7. 4     
  8. 5     // fields
  9. 6      private String name;    // name of the person
  10. 7      private int maximumBooks;    // most books the person can check out
  11. 8     
  12. 9     // constructors
  13. 10      public Person() {
  14. 11         name = "unknown name";
  15. 12         maximumBooks = 3;13     }
  16. 14     
  17. 15     // methods
  18. 16      public String getName() {
  19. 17         return name;
  20. 18     }
  21. 19     
  22. 20     public void setName(String anyName) {
  23. 21         name = anyName;   
  24. 2     }
  25. 23
  26. 24     public int getMaximumBooks() {
  27. 25         return maximumBooks;
  28. 26     }
  29. 27
  30. 28     public void setMaximumBooks(int maximumBooks) {
  31. 29         this.maximumBooks = maximumBooks;
  32. 30     }
  33. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP