Sunday, 22 February 2009

Java Miscellaneous - 1

The differences between final and static?

A final instance field must to be initialized when the object is constructed. This must be guaranteed. And the final instance field can not be modified.

A static instance field will be shared among all instance objects of the class.


How to declare a Constant?
e.g. public static final double PI = 3.14159265358979323846;


Static Characteristic:

A static method can not access a instant field and can only access static fields.

Use the Class name to invoke static methods and static fields, instead of a Object of the class.

No comments: