| Author |
Instance vs Static Variables, Methods, Constructors? Basic understanding
|
Matt Hazan
Greenhorn
Joined: Jan 27, 2011
Posts: 29
|
|
Hello everyone.
I have a test coming up very soon and I was wondering if anyone would be kind enough to explain each of the following to me in way that is easy to understand? I found some explanations online but they are a tad bit beyond my what I can comprehend as far as Java goes.
*Instance Variables (Fields)
*Instance Methods
*Static Variables (Fields)
*Static Methods
*Constructors
Thank you very much!
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
That is a very big question which isn't easy to explain. Luckily the are a lot of good tutorials out there. This is a great example. I would read that and then come back if you still have questions.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
To boil it down...
"instance" is associated with a specific object (i.e., an "instance" of a class)."static" is associated with a class, regardless of how many -- if any -- instances might be created.Constructors are code that "instantiate" (create) an Object and prepare that object for use.
But as Wouter pointed out, the implications are far reaching. Let us know if you have specific questions.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
From the tutorial that Wouter quoted, this part explains the difference between non-static and static members: Understanding Instance and Class Members.
And Providing Constructors for Your Classes explains constructors.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Instance vs Static Variables, Methods, Constructors? Basic understanding
|
|
|