class-wide global variable declared from a method?

K

Ken Kafieh

Is it possible to create a variable within a method of a class that is
accessible throughout the scope of that class without declaring it as a
field for that class?

I suspect that it goes against some OO principle. but it would be very
helpful in my current situation.

-Ken
 
C

Chris Smith

Ken said:
Is it possible to create a variable within a method of a class that is
accessible throughout the scope of that class without declaring it as a
field for that class?

I suspect that it goes against some OO principle. but it would be very
helpful in my current situation.

You've just described your goal as something that acts exactly like a
field; and I recommend using a field. As soon as you explain why you
don't want to make it a field, maybe we can discuss that.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

Sudsy

Ken said:
Is it possible to create a variable within a method of a class that is
accessible throughout the scope of that class without declaring it as a
field for that class?

Trying to duplicate the functionality of the static keyword in C?
I suspect that it goes against some OO principle. but it would be very
helpful in my current situation.

Perhaps, but even more helpful would be to perform the correct OO
analysis of the problem. Why do you need such a variable? And why
does it have to be a method variable? All methods of all instances
can "see" the class variables.

Try to describe the situation and someone here can probably help
you to see the light.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top