does static mean there is only one of?

Discussion in 'Java' started by nileppez, Aug 17, 2003.

  1. nileppez

    nileppez Guest

    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.
    nileppez, Aug 17, 2003
    #1
    1. Advertising

  2. nileppez

    Roedy Green Guest

    On 16 Aug 2003 16:18:15 -0700, (nileppez)
    wrote or quoted :

    >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.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 17, 2003
    #2
    1. Advertising

  3. nileppez

    Harald Hein Guest

    "nileppez" wrote:

    > 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.
    Harald Hein, Aug 17, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. christine bansard
    Replies:
    5
    Views:
    6,483
    Anton Spaans
    Mar 1, 2004
  2. opistobranchia

    what does 'this' mean if it static

    opistobranchia, Aug 13, 2005, in forum: C++
    Replies:
    12
    Views:
    524
    Greg Comeau
    Nov 12, 2005
  3. dolphin
    Replies:
    4
    Views:
    368
    Michael DOUBEZ
    Nov 5, 2007
  4. Mc Lauren Series
    Replies:
    5
    Views:
    375
    James Kanze
    Jun 10, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,178
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page