[Java] public, private, final and basic rules for naming.
1. 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: Means that constant, can not be modified.
3. Naming rules
- Good class name rules: Words are capitalized , e.g.
ThisIsAClass - Good mehod name rules: Spell out things where possible
Lower case, second work on is capitalized, e.g.
thisIsAFunction() - Good variables name rules: Spell out things where possible
Lower case, second work on is capitalized, e.g.
numberRuns - If it is final : All caps with underscores, e.g.
THIS_IS_A_CONSTANT - If it is class members: Begin with underscores unless they are public, e.g.
private String _thisIsAnInternalVariable
System.out.printf("%2d : [",numberRuns);
Enter value for A : 4
Enter value for B : 13
4 : [####]
13 : [#############]
[Java] public, private, final and basic rules for naming.的更多相关文章
- Java public, private, protected and default
Class Package Subclass World public y y y ...
- [Java] public, private, protected
同包不同类的成员 不同包中子类的成员 不同包非子类的成员 public √ √ √ protected √ √ × 默认 √ × × private × × ×
- 【Java关键字-Interface】为什么Interface中的变量只能是 public static final
三个关键字在接口中的存在原因:public:接口可以被其他接口继承,也可以被类实现,类与接口.接口与接口可能会形成多层级关系,采用public可以满足变量的访问范围: static:如果变量不是sta ...
- Java反射-修改private final成员变量值,你知道多少?
大家都知道使用java反射可以在运行时动态改变对象的行为,甚至是private final的成员变量,但并不是所有情况下,都可以修改成员变量.今天就举几个小例子说明. 基本数据类型 String类型 ...
- Java 基础 enum枚举类 的创建/使用/接口继承 ,以及手动创建枚举类的对象为:public static final
笔记: import java.lang.*; /**一:枚举类 : enum Season implements info { s1(),s2(),s3(),s4() }; //s1--s4 放在S ...
- Java中public,private,protected,和默认的区别
Java中public,private,protected,和默认的区别 1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以 ...
- Java中private、protected和public作用域的异同
Java中private.protected和public作用域的异同 说明:(1)private的作用范围为当前类,protected的作用范围哦不能超过其他包: (2)区别不同的作用域的不同作用范 ...
- 在JAVA中利用public static final的组合方式对常量进行标识
在JAVA中利用public static final的组合方式对常量进行标识(固定格式). 对于在构造方法中利用final进行赋值的时候,此时在构造之前系统设置的默认值相对于构造方法失效. 常量(这 ...
- Java接口中的成员变量为什么必须声明为public static final?
我想对于每个Java程序员来说,接口都不陌生,接口中的方法也经常使用.而接口中的成员变量,就显得用得少一点,而对于成员变量为什么必须声明为public static final,可能就更不清楚了,而且 ...
随机推荐
- J - S-Nim
Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as ...
- 学习vue 2.x源码笔记
1.响应式原理: 核心:Object.defineProperty,用法如下: var obj1 = {}; var initValue = 'hello'; Object.definePropert ...
- Java学习者论坛【申明:来源于网络】
学习者论坛[申明:来源于网络] 1.Java学习者论坛 2.51论坛 3.csdn论坛 4.JAVA ME论坛 地址|: http://www.javaxxz.com/ 地址|: http://bbs ...
- 将GitLab数据库从阿里云PostgreSQL RDS迁移至自建的PostgreSQL服务器
阿里云RDS目前支持的是PostgreSQL 9.4,而gitlab支持的最低版本是PostgreSQL 9.6.1,不升级PostgreSQL,gitlab就无法升级,阿里云RDS短期内不进行升级, ...
- {python--GIL锁}一 介绍 二 GIL介绍 三 GIL与Lock 四 GIL与多线程 五 多线程性能测试
python--GIL锁 GIL锁 本节目录 一 介绍 二 GIL介绍 三 GIL与Lock 四 GIL与多线程 五 多线程性能测试 一 背景知识 ''' 定义: In CPython, the gl ...
- SQLServer 索引重建
SQL Server 索引重建脚本 在数据的使用过程中,由于索引page碎片过多,带来一些不利的性能问题,我们有时候需要对数据库中的索引进行重组或者重建工作.通常这个阈值为30%,大于30%我们建议进 ...
- vue中导入外面文件(css,js)方式
有时我们需要导入外面的css文件(例如reset.css文件,bootstrap.css,jQuery.js文件),通常可通过import "name.css"的形式 对于rese ...
- arcengine实现右键菜单打开/关闭所有图层
参考资料: http://developer.51cto.com/art/201104/256774.htm 参照后自己做的: 关于右键菜单的几个有价值的网址: http://blog.csdn.n ...
- PHP之后期静态绑定
PHP后期静态绑定的(late static bindings) 理解PHP延迟静态绑定 static::中的static其实是运行时所在类的别名,并不是定义类时所在的那个类名.这个东西可以实现在父类 ...
- day0315 迭代器
一. 迭代器 1.什么是可迭代器? 除了数字和布尔值之外,其他数据类型都是可迭代对象.(字符串,列表,元组,字典,集合) 2.可迭代协议 2.1 可以被迭代要满足的要求就叫可迭代协议,可迭代的定义非常 ...