Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By allaudin
  • 1 Post By JosAH

Thread: Trouble With Variables

  1. #1
    Join Date
    Jun 2013
    Location
    United States
    Posts
    7
    Rep Power
    0

    Question Trouble With Variables

    Hello everyone!

    I have been stuck on Variables (The Java™ Tutorials > Learning the Java Language > Language Basics) for quite some time now. I believe that I have a decent understanding of each of the four types of variables listed down below, but I want to make sure that I am not incorrect. Do you see any faults with any of my explanations for each type of variable? All comments are appreciated. Thank you in advance for your help. (Took me a few hours to figure this out and write this. I am not even sure if I figured it out correctly. *sigh*)

    Summary:
    Instance Variables (Non-Static Fields): Non-Static Fields store an object's individual states in a superclass without the use of the static modifier.

    Class Variables (Static Fields): Static Fields are fields declared with a static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. All identifiers (variables) can be defined 'final', meaning that they can't be changed anymore after they have received their initial value.

    Local Variables: Local Variables are known only within a method, and then only downstream of where it is defined, and inside any block in which it was defined. Like parameters local variable are stored on the stack and are automatically disappear as soon as the method returns.

    Parameters: Parameters are the variables that are listed as part of a method declaration. Each parameter must have a unique name and a defined data type. Parameters are always classified as "variables" not "fields".
    Last edited by MarkLearningJava; 06-29-2013 at 07:19 PM.

  2. #2
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Trouble With Variables

    Just write Class Variables (Static Fields) as; Static Fields are fields declared with a static modifier ... not specifically in a subclass ...
    MarkLearningJava likes this.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: Trouble With Variables

    Leave out the 'super class' and 'sub class' stuff; that is incorrect. Also, all identifiers (variables) can be defined 'final', meaning that they can't be changed anymore after they have received their initial value.

    kind regards,

    Jos
    MarkLearningJava likes this.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    Jun 2013
    Location
    United States
    Posts
    7
    Rep Power
    0

    Thumbs up Re: Trouble With Variables

    Quote Originally Posted by allaudin View Post
    Just write Class Variables (Static Fields) as; Static Fields are fields declared with a static modifier ... not specifically in a subclass ...
    Thank you very much for responding to my thread, allaudin. I have edited my original forum post so that my explanation for Static Fields does not contain a subclass. Likewise with the superclass for Non-Static Fields. Thank you for clarifying the matter.

  5. #5
    Join Date
    Jun 2013
    Location
    United States
    Posts
    7
    Rep Power
    0

    Thumbs up Re: Trouble With Variables

    Quote Originally Posted by JosAH View Post
    Leave out the 'super class' and 'sub class' stuff; that is incorrect. Also, all identifiers (variables) can be defined 'final', meaning that they can't be changed anymore after they have received their initial value.

    kind regards,

    Jos
    Thank you very much for responding to my thread, JosAH. I have edited my original forum post so that my explanation for Non-Static Fields does not contain a superclass. Likewise with the subclass for Static Fields. I have also fixed the final statement for Static Fields. Thank you for enlightening me. Have a nice day.

Similar Threads

  1. Replies: 4
    Last Post: 02-28-2013, 04:01 AM
  2. having trouble with global variables
    By cloutier172 in forum New To Java
    Replies: 3
    Last Post: 10-31-2011, 06:22 PM
  3. Replies: 6
    Last Post: 02-15-2010, 04:31 AM
  4. Trouble with For loop and variables in a program
    By dablyz in forum New To Java
    Replies: 12
    Last Post: 05-06-2008, 04:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •