Java Learning Note –class(1)
来源:互联网 发布:数据连接老是自动打开 编辑:程序博客网 时间:2024/06/06 03:27
JavaLearning Note –class(1)
Reference: Java Tutorial (Oracle)
1.modifiers
1). comprehension
Package one: Apple 公司
Package two: Foxconn公司
Alpha: Apple 的对外关系部
Beta: Apple的研发部
AlphaSub: Foxconn 的生产部
那么,标识符可以这么理解(以 Alpha 部门为例)
public
Apple产品 (iPhone, mac,…) 人人可见
protected
Apple未公布消息(iPhone 7的配置), Apple员工都知道
Foxconn 的 AlphaSub 接到订单后(继承)也知道
default
Apple的iPhone 8研发计划, Apple员工都知道
private
Alpha研发部的内部工作, Alpha部门的人直接操作
(getter, setter: 来自其他部门的请求)
2) Tips on Choosing an Access Level.
1.Use private unless you have a good reason not to.
2.Avoid public except for constants.
Conclusion:prevent unexpected invoke.
2. class methods
class methods
(static method)
cannot access instance variables or instance methods,
unless use an object reference.????????????
cannot use this. keyword, because there is no instance.
3.Initializing
{
// whatever code is needed for initialization goes here
//for instance variable, the block will be copied to every constructor.
// with static keyword, it’s used for initialize class variable
}
class Whatever {
public static varType myVar = initializeClassVariable();
private static varType initializeClassVariable() {
// initialization code goes here
// can be reused later if you need to reinitialize the class variable.???????????
}
}
- Java Learning Note –class(1)
- Java Learning Note – inner class(2)
- Angrew. NG, Machine Learning, Class Note
- Windows Azure Learning Note (1)
- Machine Learning week 1 note
- Chapte10. Objective-C learning note 3. class summarize
- Java类加载器Learning Note
- 1: note of learning stl c++
- Learning note(1) for Windows PowerShell Tips
- The NOTE of learning ASP.NET [1]
- Machine Learning week 1 note cont.
- data.table Way - Learning Note Part 1
- Coursera Machine Learning Note - Week 1
- python learning note 1-(19-7-2017)
- Note of learning Inside the Java Virtual Machine Chapter Five
- 【java learning】Something for Class String
- Java 核心技术1NOTE
- java note-1
- C++ 中的条件语句
- QGis二次开发基础 -- 属性表格
- 回首2015,展望2016
- ASP.net开发环境Vs环安装注意要点
- android学习日记(五):ViewPager详解上
- Java Learning Note –class(1)
- 一名普通测试人员的年总结报告
- 【Java基础】采用ThreadLocal封装Connection控制事务,保证线程安全
- 263. Ugly Number
- 文章标题
- HTML标签
- 文本显示器-静态文本控件功能一览
- Java基础学习2_变量与常量
- Java基础学习1_Java基础