Results 1 to 4 of 4

Thread: Variables

  1. #1
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

    Default Variables

    I am confused about the variables. Java has 3 different variables:

    Instance variables
    Class variables
    Local variable

    Local variables are declared and used in the class. But what is the difference between class and instance variables.

    Thanks for your time.

  2. #2
    Join Date
    Dec 2007
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by mew View Post
    I am confused about the variables. Java has 3 different variables:

    Instance variables
    Class variables
    Local variable

    Local variables are declared and used in the class. But what is the difference between class and instance variables.

    Thanks for your time.
    Hi there mew

    ok, lets take this one at a time.

    Local variables are variables that are initialised and used by methods of a class. Their lifetime begins when a method is called or is running, and ends when the method has finished running.

    Class variables are variables that belong to the class, are declared once and shared by the entire class as a whole. These variables are not owned by a particular instance (object) of the class/

    Instance variables however are owned by objects or instances of the class and makes-up the data portion of the objects. Each object (instance) of the class will have its own separate copy of the instance variables.

    Hope this helps...

  3. #3
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

    Default

    Thanks definewebsites for the details.
    Your explanation cleared my confusions.
    Cheers.

  4. #4
    Join Date
    Dec 2007
    Posts
    7
    Rep Power
    0

Similar Threads

  1. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 04:58 AM
  2. Initialize variables before use
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:22 AM
  3. JSP - session variables
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-02-2007, 09:22 PM
  4. variables-methods
    By Warren in forum New To Java
    Replies: 1
    Last Post: 11-28-2007, 04:14 PM
  5. Saving Variables
    By Fish in forum New To Java
    Replies: 6
    Last Post: 06-25-2007, 08:20 PM

Posting Permissions

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