[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,可能就更不清楚了,而且 ...
随机推荐
- hadoop Codec
- 栈的C语言实现
在C++中,可以直接使用std::stack C语言实现如下: stack.c /** * @file stack.c * @brief 栈,顺序存储. * * * */ #include <s ...
- Linux----知识储备
----------------------------------------------------------------------基础---------------------------- ...
- Cross-origin plugin content from must have a visible size larger than 400 x 300 pixels, or it will be blocked. Invisible content is always blocked.
Cross-origin plugin content from must have a visible size larger than 400 x 300 pixels, or it will ...
- 质量团队在VUCA时代如何走?
如今,VUCA时代已到来.在VUCA时代(易变性volatility.不确定性uncertainty.复杂性complexity.模糊性ambiguity),面对外部环境的复杂和不确定性,测试圈是否已 ...
- F#周报2018年第51期
新闻 有经验的开发者选择F# 2018年10佳技术讲话 试用F#开发WebAssembly Fable.Remoting: 刷新访问令牌 F#开发WebAssembly现在可以使用代码补全 Rider ...
- css学习_写法规范、选择器
1.css(层叠样式表)样式主要目的(让页面更好看些) css尽量不要写内联样式,保证结构和样式分离原则: html专门负责结构,css专门负责样式. 2.css写法规范 选择器 { 属性 :值 : ...
- 在Spring的Bean注入中,即使你私有化构造函数,默认他还是会去调用你的私有构造函数去实例化
在Spring的Bean注入中,即使你私有化构造函数,默认他还是会去调用你的私有构造函数去实例化. 如果我们想保证实例的单一性,就要在定义<bean>时加上factory-method=” ...
- book_lsit
@ 学习go的轮廓.核心.难点 必看 <代码的未来> 3.2 Go ~page 123~ @ 学习内存架构.内存管理的入门.原理 必看 <操作系统之哲学原理>邹恒明 @ ...
- 2017年蓝桥杯省赛A组c++第7题(正则问题)
/* 描述:正则问题 考虑一种简单的正则表达式: 只由 x ( ) | 组成的正则表达式. 小明想求出这个正则表达式能接受的最长字符串的长度. 例如 ((xx|xxx)x|(x|xx))xx 能接受的 ...