static keyword in java
Note that:
(1) Static members are the members that
are defined as static by using ‘static’ keyword.
(2) Within a class static members can be
accessed by other static members only.
(3) In
another class , the static member(may be a variable or a method) of a given
class can be accessed by using the classname and dot operator. The commonly
used examples are Math class static methods sqrt() , pow() etc.
Consider
the program shown below.
In
the above program we directly use the class name Math with dot operator to
access its static methods. No object of class Math is created because the
methods toDegree() and sqrt() are defined as static which
is shown in the Math class definition given below.
You
can find the Math.java file here.


No comments:
Post a Comment