How to access " static data " ?
~Any data declared as static is shared by all objects.~Only single copy of static data is created and this copy is owned and maintained by class.
~Static runs only once before main.
~Benefits of of static data :
-It saves memory.
-It permits sharing.
~ To access " static data " syntax used is :
className.dataName
static{}
-static{} are used to initialize static data of a class.static function
~Function that work only and only on static data should be declared as static.~To invoke a static function syntax used is :
className.functionName(< argument >)
Example:
static import
~ It is a feature of jdk 1.5~It is used to import static data and static functions of a class.
~Types of static import are :
-import static java.lang.Math.*; // bring all files
-import static java.lang.Math.PI ; // calls the function PI
-import static java.lang.Math.pow; // calls the object pow.
No comments:
Post a Comment