static 和非static 之间的差异,只有当值在运行期间初始化的前提下,这种差异才会揭示出来.因为编译期间的值被编译器认为是相 同的. package thinking; public class FinalData { // Can be compile-time constants final int i1 = 9; static final int I2 = 99; // Typical public constant: public static final int I3 = 39
1.static关键字 经static关键字修饰的成员被该类的所有对象所共享,任意一对象对静态变量的修改其它对象都是可见的.通常通过类名来引用static成员.类加载的连接阶段将会为静态成员变量在jvm内存的方法区分配空间,并在类的初始化阶段赋初值. 一个类的static成员变量只有“一份”(存储在方法区),无论该类创建了多少对象.看如下的示例: public class StaticDemo { public static void main(String[] args) { People p
// Jakarta Commons Loggingprivate static final Log log = LogFactory.getLog(MyClass.class);The above code also shows another good practice, which is to pass the Class object to the getLog() method, instead of a string. Why the java.util.logging.Logger
1.public,protected,private是Java里用来定义成员的访问权限的,另外还有一种是"default",也就是在成员前不加任何权限修饰符.如: public class A{ void method(){}; } method就属于default权限. 这四个修饰符的访问权限如下表: -----------------------------------------------
首先定义父类和子类 public class Parent { protected static String a = "static"; final String b = "final"; public static void staticMethod(){ System.out.println("this is a static method"); } public final void finalMethod(){ System.out.p