What does 'static' indicate when we place it before a method
name? When do we want to use it? Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
Ex.
Class foo {
public static void test() {
}
public void notStatic() {
}
}
In order to call notStatic you would need to create a class instance of
foo
foo f = new foo();
f.notStatic();
You can call test without an instace of foo
test();
Note: if you manipulate class variable in a static method those class
variable must also be static
You have a wonderful Halloween!
In article <39FF0608...@cise.ufl.edu>,
Whoops! You forgot the class Chad.
foo.test();
Also the convention is to start all classes with a capital letter
e.g. Foo.test(). One of the other points about a static method (or
member/field) is that there is only one copy for the given class. So
if I had the following class
public class HalloweenKids
{
private static int lolyCount;
protected static void addLoly()
{
lolyCount++;
}
}
All the instances of HalloweenKids share their lollies so there is
only one copy of the total amount of lollies. In order to make it
clear that you are dealing with a static method you should use the
name of the class to call it and not an instance e.g.
HalloweenKids micky = new HalloweenKids();
HalloweenKids.addLoly();
not
micky.addLoly();
Cat
NEW THIS MONTH http://www.ratrobot.com/brainzilla/brainzilla.htm
What's the absolute limit of intelligence in this universe? And why
should I turn of the abflex2000 infomercials long enough to read out
it?
MY FREE APPLETS http://www.ratrobot.com/java/ratrobot_help.jar
CartoonPopUps. Put cartoon bubbles over your favourite image link
when the cursor is over them. And a simple menu applet that lets you
change the colors of the font,menu and background.
www.ratrobot.com Articles that challenge your ideas about yourself
and the world you live in.
"Chad Podoski" <cpod...@cise.ufl.edu> wrote in message
news:39FF0608...@cise.ufl.edu...
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
iQA/AwUBOf7ESih0Y2LcENUAEQIPYwCgnUAndTZX2F1MePbyq1iIAFeY/KEAoJ4l
2teLSSNJ/2sH15xT8M8z71sE
=y9lX
-----END PGP SIGNATURE-----