From: asit on
when we create an object of class type, memory is allocated in the
heap dynamically and a reference is passed to the class variable.

1>where is that variable created ??What is the scope of that
variable ???

2>As java does not have global scope, the will be no global variable.
So data memory in class programs remains unused. Is that so ???
From: John B. Matthews on
In article
<520313bd-9921-480c-b04f-95ac6ce68b74(a)z32g2000prh.googlegroups.com>,
asit <lipun4u(a)gmail.com> wrote:

> when we create an object of class type, memory is allocated in the
> heap dynamically and a reference is passed to the class variable.
>
> 1> [W]here is that variable created? What is the scope of that
> variable?
>
> 2> As java does not have global scope, the will be no global var-
> iable. So data memory in class programs remains unused. Is that so?

You can read more about (1a) Run-time Evaluation of Class Instance
Creation Expressions, (1b) Scope of Local Variable Declarations, and (2)
Finalization of Class Instances here:

<http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html>

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
From: Lew on
asit wrote:
>> when we create an object of class type, memory is allocated in the
>> heap dynamically and a reference is passed to the class variable.
>>
>> 1> [W]here is that variable created? What is the scope of that
>> variable?

One assumes you are seeking help with homework here, OP.

John B. Matthews wrote:
> You can read more about (1a) Run-time Evaluation of Class Instance
> Creation Expressions, (1b) Scope of Local Variable Declarations, and (2)
> Finalization of Class Instances here:
>
> <http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html>

In addition to John's excellent suggestion, I suggest thinking through the
question step by careful step, to make sure you understand all the teensy
little details. Surprisingly, those details actually help the big picture and
concomitant intuition.

asit:
> when we create an object of class type

That means the variable is declared something like

Class<?> clazz;

Correct?

If not, tell us what exactly you mean by an "object of class type".

> a reference is passed to the class variable

Are you saying that the variable is a class, i.e., 'static' variable?

So now you imply

static Class<?> clazz;

Again, if this isn't what you mean, please explain. Note that your questions
will make much more sense with a complete code example.

> Where is that variable created?

Well, asit, it is created in the context in which it is declared. Taking your
(implicit) class variable example, a 'static' variable is created in the class
definition for the class of which it is a part.

A (non-primitive) variable is a pointer. No variable is allowed to be
undefined at the point of use, so it must either point to 'null' or to an
object instance.

> 2> As java does not have global scope, the will be no global var-
> iable. So data memory in class programs remains unused. Is that so?

No.

--
Lew