Lesson 02 – 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> Fields for data.
2> Constructors to create objects.
3> Methods. e.g.. getters , setters.
1 package org.totoalbeginner.tutorial;
2
3 public class Person {
4
5 // fields
6 private String name; // name of the person
7 private int maximumBooks; // most books the person can check out
8
9 // constructors
10 public Person() {
11 name = "unknown name";
12 maximumBooks = 3;
13 }
14
15 // methods
16 public String getName() {
17 return name;
18 }
19
20 public void setName(String anyName) {
21 name = anyName;
22 }
23
24 public int getMaximumBooks() {
25 return maximumBooks;
26 }
27
28 public void setMaximumBooks(int maximumBooks) {
29 this.maximumBooks = maximumBooks;
30 }
31
32
33
34 }