这个课程的参考视频和图片来自youtube。
主要学到的知识点有:
- Define a method:(motivation: write one time, but use it many times)
- Access: public, private, protected
- public: Any other class can access a public field or method. (Further, other classes can modify public fields unless the field is declared as final.)
- private: Only current class can access.
- protected: Accessible within all classes in the same package and within subclasses in other packages.
2. Declaration: static, final
- static: methods can be called without declaring an object of the class first.
- final:
3. Return type: void, int, double, char, String, boolean.
- void: the method has no return value.
4. Method name:
- TODO: Good name rule:
5. Parameters:
- Variable Scope Rule: Variable or method parameter only exists inside the method body.
- When pass the parameters, only pass the value. That is why when we declare a field in a class, will start with "_", to distinguish variables with the local variable here.
- TODO: Good paramether name rule
6. Method body:
- in the block { ... }
- TODO: Good block format rule