class-wide global variable declared from a method?

Discussion in 'Java' started by Ken Kafieh, May 20, 2004.

  1. Ken Kafieh

    Ken Kafieh Guest

    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
    Ken Kafieh, May 20, 2004
    #1
    1. Advertising

  2. Ken Kafieh

    Chris Smith Guest

    Ken Kafieh wrote:
    > 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
    Chris Smith, May 20, 2004
    #2
    1. Advertising

  3. Ken Kafieh

    Sudsy Guest

    Ken Kafieh wrote:
    > 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.
    Sudsy, May 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,568
    Jon Paal
    Feb 5, 2006
  2. Web Developer

    char 8bit wide or 7bit wide in c++?

    Web Developer, Jul 31, 2003, in forum: C++
    Replies:
    2
    Views:
    569
    John Harrison
    Jul 31, 2003
  3. Disc Magnet
    Replies:
    2
    Views:
    695
    Jukka K. Korpela
    May 15, 2010
  4. Disc Magnet
    Replies:
    2
    Views:
    778
    Neredbojias
    May 14, 2010
  5. Martin Rinehart

    80 columns wide? 132 columns wide?

    Martin Rinehart, Oct 31, 2008, in forum: Javascript
    Replies:
    16
    Views:
    160
    John W Kennedy
    Nov 13, 2008
Loading...

Share This Page