• Post Reply Bookmark Topic Watch Topic
  • New Topic

Explanation for usage of word static  RSS feed

 
ashok r
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pls help me in understanding the usuage of the key word "static" in public static void main(String arg[])

[Removed email from post - UseTheForumNotEmail - Gregg Bolinger]
[ September 15, 2005: Message edited by: Gregg Bolinger ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Java In General (Beginner) Forum since this doesn't have anything to do with GUI stuff.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ashok,

I trust my response to your JApplet thread about your display name will not go ignored. Hint, hint.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static method exist @ the class level, as opposed to the object level. For example, imagine that you're a object of the class Citizen. Your object level attribute might be id_number(), because it's distinctive to just you, the object, not everyone in your country. However, you static level attribute might be the_president, because it refers to the same president that's shared to all objects of the class Citizen. Make sense?

M
 
krish reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean the the main method which is declared as static belongs to the same class in which it is created?
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means the same as "static" with any method. Namely that no object instance is required.

Example: you can call Foo.bar() but you could not do that if it wasn't static.

class Foo {
public static void bar() { ... }
}
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fallnlearn:
do you mean the the main method which is declared as static belongs to the same class in which it is created?



Yes, just as any static method would be. However, main is somewhat special, by convention, because it's the method that automatically executes when you call the class from the command line. Otherwise, it's like any other method.

M
 
Bert Bates
author
Sheriff
Posts: 8954
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ashok,

Are you asking about the concept of 'static' in general in Java, or just about why main() is static?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!