Monday, July 12, 2010

Static Import

It helps to import all the static members of a class into our class
For e.g. If u want to import all static members of Math class,Then
u can give the import statement like the following:

import static Java.Lang.Math.*;

Basic need of this type of import is u can directly call those static methods without using their class name.

for e.g: u can call absolute function in Math class as

abs(10);
No need to give like this as Math.abs(10);

2 comments:

  1. I feel that it is useful in also using the static variables like PI, E, etc....

    ReplyDelete
  2. @sujay, yes it is useful to access all static members of a class.

    ReplyDelete