DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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!




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links