Results 1 to 5 of 5
Thread: Static (having a hard time)
- 11-01-2010, 11:46 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 90
- Rep Power
- 0
Static (having a hard time)
Hello everyone.
I have just started learning Java, i'm picking up most of it very well so far EXCEPT the word Static.
i canno't for the life of me understand what this means or what it does.
the reason i picked up on it was because something like this..
this of course threw me therror about non static methods. i know i can fix this by Making myMethod static but instead of just fixing it i would like to know Why i have to do this.Java Code:class MyClass{ public static void main(String[] args){ myMethod(4); } public void myMethod (int age){ System.out.println("you are " + age " years old!"); } }
all the articles i've read aren't making sense to me as they are using big words which i think i haven't come accross yet.
Could anyone give me a simple explination as Why i use static and When to ouse it? do i need it on main ?
thanks everyone (apart from this.. i LOVE java so far)
- 11-02-2010, 12:28 AM #2
Member
- Join Date
- Nov 2010
- Posts
- 90
- Rep Power
- 0
ooooo OMG
i think i May have just understood it..
tell me if i'm right..
Static is realted to the Class and not the Object.
so if i had
int a = 0;
a++
and made 5 objects they would all have the value of 1 for a
where as if i had
static int a = 0;
a++
and i made 5 objects they would have the values
a =1
a=2
a-3... until the last one?
Yes? i so hope i got this
-
- 11-02-2010, 12:35 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 90
- Rep Power
- 0
- 11-02-2010, 07:05 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Can't make static reference to non-static method -> huh?! Simple car prgm
By enerj in forum New To JavaReplies: 7Last Post: 09-24-2010, 05:09 AM -
non-static variable grade cannot be referenced from a static context
By pictianpravin in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:59 AM -
Extreme nooby having hard time with this app
By asterix350z in forum New To JavaReplies: 2Last Post: 12-05-2007, 07:24 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks