does static mean there is only one of?

N

nileppez

is that why main() is always static?
does it mean that there can't be any instances of that method? (I mean
the class that contains main won't ever be reproduced)

am i right here?
i've never understood what static is for.
 
R

Roedy Green

is that why main() is always static?
does it mean that there can't be any instances of that method? (I mean
the class that contains main won't ever be reproduced)

You have instances of classes, not methods. There is only one class
object and main in a method of that class. It has no direct access to
the instance fields since there is no object of that class
instantiated. Main of course can instantiate objects, then use their
instance fields and methods.

see http://mindprod.com/jgloss/static.html
and http://mindprod.com/jgloss/instance.html

I think I was less tongue-tied explaining it there.
 
H

Harald Hein

nileppez said:
is that why main() is always static?
does it mean that there can't be any instances of that method?

Methods don't have instances. Classes have. These instances are called
objects.

Static methods are not related to instances, they directly belong to
the class. Because of this, you don't have to have an object before you
can call them. All you need to know is the class name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top