Simple Class Variables question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Simple Class Variables question

  1. #1
    Gary McCallum Guest

    Simple Class Variables question


    You define a "class", and inside the class you have a couple of variables.
    One variable is static, the other is not.

    Question:

    Class Test
    {
    static string name;
    int age;

    a few functions etc
    }

    Using the above, identify the class variables. Now, to MY way of thinking
    both "name" and "age" are class variables. However others say that only
    "name" is a class variable because it is static.

    Comments please!

  2. #2
    M Edvall Guest

    Re: Simple Class Variables question


    Correct about the vbls; a static vbl is a member of the class and can be accessed
    without having an instance (Object) of the class. However the your native
    vbl age can only be accessed once you have an Object of the class and can
    also only be accessed from within the same package as you have chosen "default"
    instead of e.g. private.

    "Gary McCallum" <gary.mccallum@nospam.com> wrote:
    >
    >You define a "class", and inside the class you have a couple of variables.
    > One variable is static, the other is not.
    >
    >Question:
    >
    >Class Test
    >{
    > static string name;
    > int age;
    >
    > a few functions etc
    >}
    >
    >Using the above, identify the class variables. Now, to MY way of thinking
    >both "name" and "age" are class variables. However others say that only
    >"name" is a class variable because it is static.
    >
    >Comments please!



  3. #3
    Paul Clapham Guest

    Re: Simple Class Variables question

    "name" is a class variable. "age" is an instance variable. This is the
    terminology used in "The Java Language Specification" by Gosling, Joy, and
    Steele, which you can download from
    http://java.sun.com/docs/books/jls/index.html.

    PC2

    Gary McCallum <gary.mccallum@nospam.com> wrote in message
    news:39ef12f3$1@news.devx.com...
    >
    > You define a "class", and inside the class you have a couple of variables.
    > One variable is static, the other is not.
    >
    > Question:
    >
    > Class Test
    > {
    > static string name;
    > int age;
    >
    > a few functions etc
    > }
    >
    > Using the above, identify the class variables. Now, to MY way of thinking
    > both "name" and "age" are class variables. However others say that only
    > "name" is a class variable because it is static.
    >
    > Comments please!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center