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!
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!
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!