Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instance vs Static Variables, Methods, Constructors? Basic understanding  RSS feed

 
Matt Hazan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Jesper de Jong
    Java Cowboy
    Sheriff
    Posts: 16028
    87
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!