Sep 12, 2009

Static and transient in java

Static : access modifier.
Signa: Variable-Static int b; Method- static void meth(int x)

When a member is declared as Static, it can be accessed before any objects of its class are created and without reference to any object. Eg : main(),it must call before any object exit.
Static can be applied to Inner classes, Variables and Methods.
Local variables can’t be declared as static.
A static method can access only static Variables. and they can’t refer to this or super in any way.
Static methods can’t be abstract.
A static method may be called without creating any instance of the class.
Only one instance of static variable will exit any amount of class instances.


Transient : access modifier
Transient can be applied only to class level variables.
Local variables can’t be declared as transient.
During serialization, Object’s transient variables are not serialized.
Transient variables may not be final or static. But the complies allows the declaration and no compile time error is generated.

Try these codes in your netbooks and leave your comments if any....