Java Reference
In-Depth Information
The output from the program is shown here:
As you can see, the static variable y is shared by both ob1 and ob2 . Changing it affects the
entire class, not just an instance.
The difference between a static method and a normal method is that the static method
is called through its class name, without any object of that class being created. You have
seen an example of this already: the sqrt( ) method, which is a static method within Java's
standard Math class. Here is an example that creates a static method:
Search WWH ::




Custom Search